Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    C++ coding help -- Having issues with an if/else statement

    /sigh

    I'm having issues with the following code:

    Code:
    #include <iostream>
    using namespace std;
    
    int main (int argc, char * const argv[])
    {
    	string next;
    	string res1;
    	string res2;
    	string res3;
    	string res4;
    	string res5;
    	string res6;
    	string res7;
        cout << "Welcome to NAMEGAME" << endl;
    	cout << "Your lit cigarette is the only light in your cramped, \nsqualid room. You’re sitting up-right in your bed, \nstaring into the darkness. Your room has only three \nwalls, the forth wall is made entirely of the door. \nLight spills in from the sides of the door, slightly \nilluminating your ceiling, floor, and walls. \nYou face towards your door." << endl;
    	cout << "Type 'Next' to continue reading." << endl;
    	cin >> next;
    	if (next == "Colon")
    	{
    		cout << "lol, colon" << endl;
    		goto LINE3;
    	}
    	else 
    	{
    		cout << "\n";
    		goto LINE3;
    	}
    LINE3:cout << "Ash drops from your cigarette to your bed, and you \nwipe it off with your hand. It’s burned down to the \nbutt, and you flick it onto the floor. You search \nyour pocket for another. You brush aside your LIGHTER \nand find your pack of Marlboros. It feels suspiciously \nlight, and indeed, on further inspection it is empty. \nYou curse and throw it to the floor. You dig in your \nPILLOW CASE for some money, and take out your \nlast few bills and coins adding up to around $9.50. \n(Enough for a pack, and you don’t feel like counting all the little coins). \nYou shove the money into your short’s pocket. \nFloor 7 Landing lies SOUTH." << endl;
    restart:std::getline(std::cin,res1);
    	if (res1 == "SOUTH" || res1 == "South" || res1 == "south" || res1 == "GO SOUTH" || res1 == "Go SOUTH" || res1 == "go south" || res1 == "GO south" || res1 == "Go South" || res1 == "go SOUTH" || res1 == "S" || res1 == "s")
    	{
    		cout << "You went SOUTH, arriving at the Floor 7 landing. DESCRIPTION1. OPTIONS1." << endl;
    	}
    	else
    	{
    		cout << "I'm sorry, could you try re-phrasing that?\n" << endl;
    		goto restart;
    	}
        return 0;
    }
    When I type "Next" to continue (While I'd rather have it be a NULL input, so I can hit Enter to continue, that's just a side thing.), it does it, but also puts the else condition of the NEXT if/else statment,

    Okay, I managed to fix it by instead of using cin << I used std::getline(std::cin,STRING)

    I could still use help in finding a way to make it null rather than typing Next.
    Last edited by MrNotkewl; 08-20-2008 at 07:58 AM.

  • #2
    Regular Coder
    Join Date
    May 2002
    Location
    Virginia, USA
    Posts
    621
    Thanks
    0
    Thanked 6 Times in 6 Posts
    Do you mean something like:


    Code:
    std::cout << "Hit <enter>" << std::endl;
    std::cin.get();
    ?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •