...

View Full Version : C++ coding help -- Having issues with an if/else statement



MrNotkewl
08-20-2008, 06:16 AM
/sigh

I'm having issues with the following 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.

Celtboy
08-20-2008, 01:30 PM
Do you mean something like:




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


?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum