![]() |
|
#1
|
|||
|
|||
C++ If/Else StatementOkay, im making a "simple" program using C++. In it I have a thig where I have simple yes/no answers, and other things like that. In the begining the user is asked, do you want to start? If someone answers yes, it starts. if they answer no, it sends the to the fatal "Press any btton to exit". how do I do that exactly, so that I do not need 500 lines of code in the "if" statement for yes.
![]() |
|||
|
#2
|
|||
|
|||
Re: C++ If/Else StatementQuote:
CPP / C++ / C Code:
But the real solution, I think, is to reorganize your program. I would venture a guess that if there really are 500 lines of code in your else part, you don't make much use of functions? Perhaps you're not that far yet, but you might as well take a look at functions, since they really do make your life easier. Does your else part perform some repetitive tasks? You said you have simple yes/no answers, so I take it your program is asking for input at several places? Do you have that separated into a function? One solution is to put the whole (or as much as possible) processing of the program into a separate function. Then you could do something like CPP / C++ / C Code:
... But in the end, that code has to be SOMEWHERE. Does it really make a difference whether it's directly in that if/else part or just in a function called from the if/else part? Or just not in an if/else part at all? If you wanted, you could show your code and people could perhaps give pointers on what to separate into functions to reduce the code size (that is, if you haven't already). |
|
#3
|
|||
|
|||
Re: C++ If/Else StatementYe I do use functions, and it is more then just the yes no answers. It is a sort of simple game I am working on, but I just couldn't figure out how to end the program if they answered no or quit for the starting the game. Thank you very much for the help.
|
Recent GIDBlog
Accepted for Ph.D. program by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| I need help on My SQL Database Creation Statement | asdfg | MySQL / PHP Forum | 6 | 08-Mar-2008 05:13 |
| Is "else if" a separate kind of statement in Java? | anders | Java Forum | 1 | 20-Apr-2007 16:09 |
| Fortran problem... | Justin Fox | Miscellaneous Programming Forum | 6 | 24-Oct-2006 16:30 |
| Need a bit of help with switch() | Caibre | C Programming Language | 5 | 12-Apr-2005 18:02 |
| C if/else statement problem | JYGUTI | C Programming Language | 1 | 28-Mar-2005 06:58 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The