![]() |
|
#1
|
|||
|
|||
if loop problemsI am having problems with the following progamany ideas?
CPP / C++ / C Code:
Last edited by admin : 11-Oct-2005 at 21:17.
Reason: Please insert your C code between [c] & [/c] tags
|
|
#2
|
|||
|
|||
Re: if loop problemsThe compiler is c++ and here are the program requirements.
rite a C++ program that shows the following menu: P[rime] C[onversion] Q[quit] • If you select "P or p" You should invoke a user-defined function, int prime (void) to prompt the user to enter a number and determine whether or not the number is a prime number. Print the number in function main (). (Hint: you may use modulus, % operator) • If the user select "C or c" You should invoke a user-defined function void convert (void) to convert from Fahrenheit to Celsius or from Celsius to Fahrenheit. In this function prompt the user for the following submenu: 1. Convert from Fahrenheit to Celsius 2. Convert from Celsius to Fahrenheit The user should choose one of the options. Then prompt the user for appropriate temperature and then display corresponding temperature. Use the conversion equations below: F = (9/5)C + 32 C = (5/9) (F-32) • If the user selects “q or Q” then your program should terminate. |
|
#4
|
||||
|
||||
Re: if loop problemsHi bco
Welcome to the GID Forums. If is not a Loop. for, while, do while are loops. If is just a statement to check whether the condition is true or not. The main error in your program is that you should put the cin>>Type inside your loop. you should get the input from the user everytime isnt it? You have to use functions as you said. The function declaration should be of this type: CPP / C++ / C Code: CPP / C++ / C Code:
f(type varname1, type varname2, . . . , type varnameN) For example consider your prime number function. it should be like this: CPP / C++ / C Code:
You can construct a similar function for Celsius/fanrenheit conversion. then in your main program use a do while loop so that you get input from the user atleast once. You may use this method: CPP / C++ / C Code:
and your CPP / C++ / C Code:
Regards, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#5
|
|||
|
|||
Re: if loop problemsThis is what I have so far. I am sure I am missing something however making progress.
CPP / C++ / C Code:
Last edited by admin : 11-Oct-2005 at 21:19.
Reason: Please insert your C code between [c] & [/c] tags
|
|
#6
|
|||
|
|||
Still having troubleI have the program working however I have a few problems.
1. When i quit the progam it continues to loop invalid entry. 2. when I check for a prime number, once I enter a non prime number it will not detect the prime number anymore. Below is the C++ code I have so far. CPP / C++ / C Code:
Last edited by admin : 11-Oct-2005 at 21:26.
Reason: Please insert your C code between [c] & [/c] tags
|
|
#7
|
|||
|
|||
Re: Still having troubleQuote:
CPP / C++ / C Code:
But, CPP / C++ / C Code:
Quote:
CPP / C++ / C Code:
|
|
#8
|
|||
|
|||
Re: Still having troubleShould i use d=1++
|
|
#9
|
|||
|
|||
Re: Still having troubleQuote:
Some information on "lvalue" http://cplus.about.com/od/cprogrammi...def_lvalue.htm You might just try reseting "d" to the original value if you do not need it to keep the value "1". CPP / C++ / C Code:
|
|
#10
|
|||
|
|||
Re: Still having troubleThanks for the help. everything is looking good exept fot the termination of the program. If i add a break then it will not loop back.
CPP / C++ / C Code:
Last edited by admin : 11-Oct-2005 at 21:25.
Reason: Please insert your C code between [c] & [/c] tags
|
Recent GIDBlog
Halfway done! by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Array 1 dimensional help please asap | lion123 | C Programming Language | 10 | 18-Feb-2005 21:53 |
| messy loop help please | sammacs | C Programming Language | 6 | 26-Nov-2004 15:18 |
| Nested for loop with function | Tori | C++ Forum | 11 | 08-Nov-2004 13:02 |
| Loop problems | ambeco | C++ Forum | 8 | 03-Mar-2004 10:02 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The