• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • About
  • Life
  • Tech
  • Travel
  • Work
  • Questions
  • Contact

Welcome

.

problem with including header file in c++ program? [closed]

April 10, 2020 by

Questions › problem with including header file in c++ program? [closed]
0
Vote Up
Vote Down
Garmaine asked 4 years ago
Closed. This question is off-topic. It is not currently accepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 8 hours ago.

I recently created a text based battle simulator in python. It was cool and all, but i am more interested in c++, so i wanted to port it into that language, in the form of a header file that i already used for other things. However, i have no idea how the header system works in c++. I tried removing the dash symbol from the name and replacing it with an underscore, but that didn't work. I even tried putting the code into a namespace in the header, but it said that some of the code that i put in the namespace didn't belong in the namespace when i was trying to compile the test program. In other words, i am trying to include a header file in a c++ program, but I don't know how to do so, as everything i try won't work. Also, when it looks through the header file for errors, it takes a look at one of the classes and notices an integer function. It then tells me that it can't convert type int to type int. Why that happened, it makes no sense to me.

PS: I am using mingw32 on mingw64 gcc to compile this program. If anyone has an answer or might have an answer, i'll be sure to reply (at some point). Also, if anybody needs reference code, then i might or might not be able to give it to you.

EDIT: By port i mean rewriting the code in c++

UPDATE: I've reached my question limit so i had to squeeze this one in. How am i able to break out of a while loop? gcc gives me an error that tells me that break isn't meant for loops and switch statements.

UPDATE: This is the code for a header file that includes the code for the battle function. I don't think it is much of a problem with the function though:

string Battle(string playerName, string enemyName, int playerHealth, int enemyHealth, int playerSpecial, int enemySpecial)
{

    int old_ehp = enemyHealth;
    int old_php = playerHealth;

    cout << "A challenger aproaches. " << enemyName << " wants to fight!" << endl;
    cout << "Let the battle begin." << endl;

    do
    {

        // players turn text
        cout << playerName << "'s turn." << endl;
        cout << "(1). Attack (2). Special (3). Give up" << endl;

        cout << "> ";

        // attack info

        int attack;
        cin >> attack;

        // Check if int(attack) equals 1
        if(attack == 1)
        {

            cout << "Player attacks!" << endl;

            // Define critical hit
            int critical = rand() % 4;

            if(critical == 3)
            {

                cout << "Critical hit!" << endl;
                enemyHealth -= 4;

            }
            enemyHealth -= 3;

        } else if(attack == 2)
        {

            cout << "Player uses special attack!" << endl;
            int critical = rand() % 6;
            if(critical == 5)
            {

                cout << "Critical hit!!!" << endl;
                enemyHealth -= 5;

            }
            enemyHealth -= playerSpecial;

        }

        cout << enemyName << "'s turn." << endl;
        cout << enemyName << " has decided what attack he/she will use." << endl;

        attack = rand() % 6;

        if(attack != 5)
        {

            cout << enemyName << " attacks!" << endl;

            int critical = rand() % 4;

            if(critical == 3)
            {

                cout << "Critical hit!" << endl;
                playerHealth -= 4;

            }
            playerHealth -= 3;

        } else {

            cout << enemyName << " uses special attack!" << endl;

            int critical = rand() % 6;

            if(critical == 5)
            {

                cout << "Critical hit!" << endl;
                playerHealth -= 5;

            }
            playerHealth -= enemySpecial;

        }

        int healer = rand() % 20;

        if(healer == 0 or healer == 1)
        {

            cout << playerName << " found HP revive!" << endl;
            playerHealth += 5;

        } else if(healer == 19) {

            cout << playerName << " found HP super revive!" << endl;
            playerHealth = old_php;

        }

        healer = rand() % 40;
        if(healer == 0 or healer == 1)
        {

            cout << enemyName << " found HP revive!" << endl;
            enemyHealth += 5;

        } else if(healer == 39)
        {

            cout << enemyName + " found HP super revive!" << endl;
            enemyHealth = old_ehp;

        }

        int magicFlute = rand() % 100;

        if(magicFlute == 72)
        {

            cout << playerName << " obtained magic flute!" << endl;
            cout << playerName << " uses the magic flute to one hit K.O. " << enemyName << "!!!" << endl;
            enemyHealth = 0;

        }

        if(playerHealth < 0){
            cout << playerName << "'s health is 0" << endl;}
        else{
            cout << playerName << "'s health is " << playerHealth << endl;
        }
        if(enemyHealth < 0)
        {

            cout << enemyName << "'s health is 0" << endl;

        } else {

            cout << enemyName << "'s health is " << enemyHealth << endl;

        }

    } while(enemyHealth > 0 or playerHealth > 0);

    if(playerHealth <= 0)
    {

        cout << "You lost the battle." << endl;
        break;

    }
    else if(enemyHealth <= 0)
    {

        cout << "You won the battle." << endl;
        break;

    }

};

My problem is that i don't know how to include this into a test program and use the function inside of the header file.

Are you looking for the answer?
Original Question and Possible Answers can be found on `http://stackoverflow.com`

Question Tags: c++

Please login or Register to submit your answer




Primary Sidebar

Tags

Advancements best Business strategies commercial convenience economic Finances Cognitive decline Financial growth firm Future Hidden Gems Home hydration Impact Innovations lighting line of work Mental health Must-See New York City office patronage Productivity profession Profitability tips Profit optimization pursuit recreation Revenue enhancement romance sippy cups social station Technological breakthroughs technology toddlers trading transaction Treasures Uncover undertaking Well-being Wonders Work Young onset dementia

Newsletter

Complete the form below, and we'll send you all the latest news.

Footer

Footer Funnies

Who knew that reading the footer could be such a hilarious adventure? As we navigate websites, books, and documents, we often stumble upon the unassuming space at the bottom, only to discover a treasure trove of amusement. In this side-splitting compilation, we present 100 jokes that celebrate the unsung hero of content – the footer. Get ready to chuckle, giggle, and maybe even snort as we dive into the world of footnotes, disclaimers, and hidden comedic gems. Brace yourself for a wild ride through the footer!

Recent

  • Unveiling the Enigma: Almost-Magical Lamp Lights Highway Turns
  • The Impact of Young Onset Dementia on Employment and Finances: Optimizing Post-Diagnostic Approaches
  • 11 Wonders of 2023 Technological Breakthrough – Unveiling the Future
  • Work from Home and Stay Mentally Sane – Achieve Productivity and Well-being
  • Hidden Gems of New York City – Uncover the Must-See Treasures!

Search

Tags

Advancements best Business strategies commercial convenience economic Finances Cognitive decline Financial growth firm Future Hidden Gems Home hydration Impact Innovations lighting line of work Mental health Must-See New York City office patronage Productivity profession Profitability tips Profit optimization pursuit recreation Revenue enhancement romance sippy cups social station Technological breakthroughs technology toddlers trading transaction Treasures Uncover undertaking Well-being Wonders Work Young onset dementia

Copyright © 2023