how do I stop the code from 1. accepting inputs as both 1 and 2, and 2. stop it from running endlessly to 0

Viewed 33

I just started trying to do big paragraphs of code a little while ago after learning the very very small basics. Now, when I try to compile the code I'm about to send, the code refuses to take the input. Instead, it read what I sent it as both, 1 and 2, and ran the code like that. It's also endlessly running into 0 which I found to be line 30, but I can't seem to find a way to keep that function while allowing the code to stop and continue. I've tried using a do, while loop while keeping the 1 (button) as the end goal, but it either just keeps looping endlessly or doesn't post at all until I send in 1. Any tips will be helpful.

Update: Since you people wanted clarity, here it is. The code is meant to be two answer game. 1, ends the game by pressing a figurative button that saves the world. 2, continues the game by one minute by waiting. The problem I have is trying to loop the wait (2) by setting it to continue the game when it recognizes the 2, and stop it when it sees 1. Also

if (WorldTime = 80, WorldTime > 0, Answer = 2) { WorldTime - 1; cout << "You waited. You have " << WorldTime << " Minutes until the end of the world"; }

This is meant to continuously decrement the World Time every time wait is input. Thing is, it won't loop with the things I've tried. I did get a fix to my other problem so here is the updated code. I just need to make it loop. Again, I'm not saying that my loop won't work, I'm saying that I can't find a way to make it loop. Also, in response to another comment, int WorldTimeEND = 80 - WorldTime; is used ONLY for a "score". It shows how many minutes it took for you to press the button. That's why it exists. Finally, if (WorldTime < 35 && WorldTime > 0) is to be just used as a side comment. When WorldTime goes under 35, it just states that the world is crumbling, working as a replacement for the previous text. Hopefully this i enough clarity?


#include <iostream>
#include <sstream>

using namespace std;

int main()
{
    int WorldTime = 80;
    int WorldTimeEND = 80 - WorldTime;
    int Answer;
    cout << "The world will end in " << WorldTime << " Minutes. Will you wait, or press the red button? Type 1 to press it or 2 to wait";
    std::cin >> Answer;


if (WorldTime > 0 && Answer == 1)
{
    cout << "The World was saved in " << WorldTimeEND << " Minutes";
}



if (WorldTime == 80 && WorldTime > 0 && Answer == 2)
{
    WorldTime --; 1;
    cout << "You waited. You have " << WorldTime << " Minutes until the end of the world";
}
if (WorldTime < 35 && WorldTime > 0)
{
    cout << "You feel the earth cruble under you. Hurry up. Press the button... or, do you want everyone to die?( " << WorldTime << " Minutes remain";
}
if (WorldTime = 0 && WorldTime < 0)
{
    cout << "Its over. The world ended.";
}
    return 0;

}

0 Answers
Related