![]() |
Simple if statement question :(
I haven't used C++ in a while, and right when I get back to starting up again, I fall upon this simple error in my simple code here:
:
`;' before '(' token expected identifier before '(' token Any help, please? |
Re: Simple if statement question :(
Error:
if (sum > 10) && (sum >50) Should be: if ( (sum > 10) && (sum >50) ) |
Re: Simple if statement question :(
Silly me :icon_redface:
Thanks... and just out of curiosity, how can I get the program to go back to the start after ending instead of "Press any key to continue" and the command prompt exits? |
Re: Simple if statement question :(
Try changing system("PAUSE"); to cin.get();
|
Re: Simple if statement question :(
Okay- all that happens is that when I input all 4 numbers the screen just exits.
|
Re: Simple if statement question :(
1. You don't need stdio.h (it should be cstdio for c++ anyway).
2. iostream.h should be iostream 3. As for your last question: place everything from the first to the last cout in a while (true) { } loop or something of the sort.4. Don't forget to return 0; and close main. |
Re: Simple if statement question :(
Thanks, peaceofpi. That was helpful and I've fixed my problem; yes I want to get deeper and more complicated in this simple program I have built.
:
But what I have done is basically reversed the Y/N if statements: :
|
Re: Simple if statement question :(
:
if (yesno == "Y") {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: ";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). |
Re: Simple if statement question :(
Thanks a lot :)
I will also try proper indenting techniques as well. |
Re: Simple if statement question :(
Here's your code indented and fixed up a bit.
:
|
| All times are GMT -5. The time now is 12:30 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC