![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Jul 2005
Posts: 66
Rep Power: 4
![]() |
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:
C++ Syntax (Toggle Plain Text)
`;' before '(' token expected identifier before '(' token Any help, please? |
|
|
|
|
|
#2 |
|
Game engine designer
Join Date: May 2005
Location: Sweden
Posts: 297
Rep Power: 4
![]() |
Re: Simple if statement question :(
Error:
if (sum > 10) && (sum >50) Should be: if ( (sum > 10) && (sum >50) )
__________________
http://www.klarre.se |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Jul 2005
Posts: 66
Rep Power: 4
![]() |
Re: Simple if statement question :(
Silly me
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? |
|
|
|
|
|
#4 |
|
Game engine designer
Join Date: May 2005
Location: Sweden
Posts: 297
Rep Power: 4
![]() |
Re: Simple if statement question :(
Try changing system("PAUSE"); to cin.get();
__________________
http://www.klarre.se |
|
|
|
|
|
#5 |
|
Programmer
Join Date: Jul 2005
Posts: 66
Rep Power: 4
![]() |
Re: Simple if statement question :(
Okay- all that happens is that when I input all 4 numbers the screen just exits.
|
|
|
|
|
|
#6 |
|
hi: for(;;) goto hi;
|
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.
__________________
How do you play Religious Roulette? Stand around in a circle and blaspheme till someone gets struck by lightning. |
|
|
|
|
|
#7 |
|
Programmer
Join Date: Jul 2005
Posts: 66
Rep Power: 4
![]() |
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.
C++ Syntax (Toggle Plain Text)
But what I have done is basically reversed the Y/N if statements: C++ Syntax (Toggle Plain Text)
|
|
|
|
|
|
#8 |
|
Programming Guru
![]() |
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).
__________________
Waterloo's Canadian Computing Competition (CCC) - Stage 2 Problems, Solutions, and Test Data Last edited by Sane; May 4th, 2008 at 11:42 AM. |
|
|
|
|
|
#9 |
|
Programmer
Join Date: Jul 2005
Posts: 66
Rep Power: 4
![]() |
Re: Simple if statement question :(
Thanks a lot
![]() I will also try proper indenting techniques as well. |
|
|
|
|
|
#10 |
|
hi: for(;;) goto hi;
|
Re: Simple if statement question :(
Here's your code indented and fixed up a bit.
c++ Syntax (Toggle Plain Text)
__________________
How do you play Religious Roulette? Stand around in a circle and blaspheme till someone gets struck by lightning. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| very simple question. make button change number in edit box | nickm | Delphi | 2 | Apr 29th, 2006 10:47 PM |
| A simple programming question | punter | C# | 8 | Jan 5th, 2006 4:04 PM |
| A simple question | Master | C++ | 9 | Dec 24th, 2005 2:20 PM |
| Simple c# question | nez | C# | 8 | Jul 1st, 2005 6:29 PM |
| Simple (stupid cause I don't know it) basic question | massive-war | C++ | 17 | Apr 11th, 2005 11:03 PM |