View Single Post
Old May 4th, 2008, 11:31 AM   #8
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,799
Rep Power: 5 Sane will become famous soon enough
Re: Simple if statement question :(

if (yesno == "Y") {
return 0;
}
else if (yesno == "N") {
system("pause");
}

The command "return" exits from main. Therefore, if they enter "Y", main is exited. You want the program to terminate if they hit "N", otherwise ignore the input.

        cout << "Try again? Y/N: ";
        cin >> yesno;
        if(yesno == "N") {
            return 0;
        }
    }
}

By the way, you should probably practice proper indenting style. It makes code a lot more readable. One popular method is 4 spaces per block, keeping the open bracket on the same line as what opens the block, and the close bracket on a new line a level down (as shown in my posted code).

Last edited by Sane; May 4th, 2008 at 11:42 AM.
Sane is online now   Reply With Quote