![]() |
|
#1
|
|||
|
|||
problem with if statementsthis is soposed to be an all in one convertion program it runs just dosent do what i want it to. The problem is thats is going in order from 1 to 2 to 3. But i want it to jump to what number you type not for it to just run from begging to end. how do i get the if statements to work correctly? This is not homework for school im learing c++ on my free time.
CPP / C++ / C Code:
|
|||
|
#2
|
||||
|
||||
Re: problem with if statementsYou have semicolons after all your if statements, which means that they won't actually have any effect. Those semicolons all need to go:
CPP / C++ / C Code:
That does not fix your problem, though. Now if you enter something other than 1, the line immediately after the if statement will not be executed, but everything after that will be. Curly braces will solve that problem: CPP / C++ / C Code:
Finally, you only want one to do one conversion, so you should use if-else statements: CPP / C++ / C Code:
Some other tips: You may want to consider using a switch statement because they were designed for this kind of thing. It's not a great idea to use the same variable to store the menu selection result and measurement to convert. You should probably make a different variable (an int) for the menu selection. If you wanted to consider a larger set of conversions, manually coding every possible conversion would not be a good idea. It would be better to pick a unit for internally storing distances, convert the input units to the internal units, and then convert the internal units to the output units. For example, if you choose to use feet internally, you might store two constants inchesToFeet and milesToFeet. Then the conversion from inches to miles would be would be: CPP / C++ / C Code:
__________________
www.blake-foster.com |
Recent GIDBlog
Vista ?Widgets? on Windows XP by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Apache Web Server newbie problem | niss3 | Apache Web Server Forum | 1 | 13-Apr-2009 18:38 |
| Graphic problem in Unreal Tournament 2004 | zerox | Computer Software Forum - Games | 10 | 09-Oct-2005 12:31 |
| Runtime Problem involving "printf" in C Program | supamakia | C Programming Language | 2 | 09-Oct-2005 10:09 |
| a significant problem after installing Xp | mohammad | Computer Software Forum - Windows | 10 | 09-Aug-2005 07:03 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The