Can't figure out why it wont stop looping

can definition
can synonym
can verb
can y
can noun meaning
can band

Image of error It asks the question twice, just needing it asked once but the loops runs good and in-unison with the other parts of the program. Thank you for any ideas or suggestions, college class btw!

In a new program create the following functions: Story, AskYesNo; one string argument named question, RollDie; one int parameter named sides with a default value of 6, Ending, Adventure, obviously main.

Create the following global variables: health, totalTreasure.

The game should run as follows:

The player is told a story prompting them to seek treasure on an adventure. The player is asked if they would like to go adventuring. If the player says yes, numbers for an enemy attack, their own block, and an amount of treasure are randomly generated. If the player's block is higher than the enemy attack, they have successfully blocked and they receive the treasure. However, if the attack is higher, that number is subtracted from their health and they do not get the treasure. The player is then told their health and amount of totalTreasure and asked if they would like to adventure again. They can continue to adventure as long as their health is greater than zero, at which point the ending is run and they are told that they are dead If they instead quit before their health is zero, they are told how much health they have and how much treasure they ended up with.

// Global variables
int playerHealth = 15;
int playerTreasure = 0;

// Function Prototypes
void ending();
void story();
void adventure();
int rollDie(int sides = 6);

int main() { //My so called storyboard lol
    return 0;

void ending() {
    if (playerHealth <= 0) {
        cout << endl;
        cout << "Your out of health! :(\n";
        cout << "The treasure you end up with is " << playerTreasure << " pieces!\n";
        cout <<"Thanks for adventuring!\n";
    } else { // if (askYesNo("Do you want to keep adventuring? (y/n)") == "n")
        cout << "You retired from adventuring!\n";
        cout << "You retired with " << playerTreasure << " treasure pieces!\n";

void story() {
    cout << "You wake up in a forrest, by yourself\n";
    cout << "You only have " << playerHealth << " health points left.\n";
    cout << endl; 

string askYesNo(string givenQuestion) {
    string input; 
    do {
        cout << givenQuestion << endl;
        cin >> input;
    } while (input != "y" && input != "n");
    return input;

int rollDie(int sides) { 
    return rand() % sides + 1;

void adventure() {
    do {
        if (askYesNo("Do you want to keep adventuring? (y/n)") == "y")
            int enemyAttack = rollDie(100);
            int playerBlock = rollDie(100);
            if (enemyAttack > playerBlock)
                playerHealth -= 3;
                cout << "The enemy attack points is " << enemyAttack << "\n";
                cout << "Your player block is " << playerBlock << "\n";
                cout << "Your current health is " << playerHealth << " .\n";
                cout << "You did not gain any treasure\n"; 
            } else if (playerBlock >= enemyAttack)
                playerTreasure += rollDie(6);
                cout << "The enemy attack points is " << enemyAttack << "\n";
                cout << "Your player block is " << playerBlock << "\n";
                cout << "You have blocked!\n";
                cout << "You gain treasure! your current treasure is " << playerTreasure << " \n"; 
        } else {
            cout << "Your current health is " << playerHealth << " .\n";
            cout << "Your current amout of treasure is " << playerTreasure << " \n";
    } while(playerHealth > 0 && askYesNo("Do you want to keep adventuring? (y/n)") == "y");

No error messages.

if (enemyAttack >= playerBlock)
else if (playerBlock < enemyAttack)

I think, for a start, you should fix that combination of conditions. The second can never be true if the first is false.

Since you state that "treasure is never gained" and the gaining is in the code that can never be executed, that will fix at least one of your issues.

I suspect what you're after is something like:

if attack > block:
    lose health
else if attack < health:
    gain treasure
    do neither

With suitable output in all cases of course.

Can, Can may refer to: Contents. 1 Containers; 2 Music; 3 Other; 4 See also. Containers[edit]. Aluminum can · Drink can · Oil can · Steel and tin cans · Trash can  Can definition, to be able to; have the ability, power, or skill to: She can solve the problem easily, I'm sure. See more.

The problem is with the askYesNo() function called twice. If you are calling askYesNo() inside the while() condition, then no need to call askYesNo() again inside the if(). So, it's basically repeating that.

The Official CAN / Spoon Records Website, VerbEdit. can (third-person singular simple present can, present participle -, simple past could, past participle (obsolete except in adjectival use) couth). Define can. can synonyms, can pronunciation, can translation, English dictionary definition of can. to be able to, have the power or skill to: I can take a bus to the

I think you should use simple while like this:

while (playerHealth > 0)
    if (askYesNo("Do you want to keep adventuring? (y/n)") == "y")
        // do the yes part
        // do no part
        return; // this will break your while

Can, can meaning: 1. to be able to: 2. used to say that you can and will do something: 3. to be allowed to: . Learn more. can definition: 1. to be able to: 2. used to say that you can and will do something: 3. to be allowed to: . Learn more.

can, 1.4Used to indicate that something is typically the case. 'antique clocks can seem out of place in modern homes'. More example sentences. 110 synonyms of can from the Merriam-Webster Thesaurus, plus 97 related words, definitions, and antonyms. Find another word for can. Can: to bring (as an action or operation) to an immediate end.

CAN, can. (kæn). n. 1. a container, esp for liquids, usually of thin sheet metal: a petrol can;  Can means someone or something knows how to, is able to, is likely to or has the right to do something. An example of can is someone knowing how to play the piano. An example of can is a cat being able to paint. An example of can is a car that usually starts.

Can, Can-Am offers a complete lineup of Off-Road vehicles (ATV, Side-by-Side) and 3-​wheel motorcycles (Spyder or Ryker). Choose your playground now and enjoy  Looking for online definition of CAN or what CAN stands for? CAN is listed in the World's largest and most authoritative dictionary database of abbreviations and acronyms The Free Dictionary