menu
-
Please help Here is my code. I was able to modified to go to main menu. But If user enter a value outside the range it should not go to the main menu. It should display only: cout<<"Please enter 1 or 2 (3 to exit program):"; cin>>choice; #include //using namespace std; int main(void) { int choice; float c; //Declare variable to be displayed. float f; //Question:Will it be the best practice to do this: float c=0? //Question:I used float, but I am not sure if in this case better to use int or double? for(;;) // empty to promt a user to enter correct choice value { cout<<"Please select the task to perform:"<>choice; switch (choice) { // use switch in order to do validation and calculation case 1: { cout<<"Enter value in Fahrenheit:" ; cin>>f; c=((f-32)*5/9); cout<<"The value in Centigrade is:"<>c; f=((c+32)*9/5); cout<<"The value in Fahrenheit is:"<
-
Please help Here is my code. I was able to modified to go to main menu. But If user enter a value outside the range it should not go to the main menu. It should display only: cout<<"Please enter 1 or 2 (3 to exit program):"; cin>>choice; #include //using namespace std; int main(void) { int choice; float c; //Declare variable to be displayed. float f; //Question:Will it be the best practice to do this: float c=0? //Question:I used float, but I am not sure if in this case better to use int or double? for(;;) // empty to promt a user to enter correct choice value { cout<<"Please select the task to perform:"<>choice; switch (choice) { // use switch in order to do validation and calculation case 1: { cout<<"Enter value in Fahrenheit:" ; cin>>f; c=((f-32)*5/9); cout<<"The value in Centigrade is:"<>c; f=((c+32)*9/5); cout<<"The value in Fahrenheit is:"<
You could create another function to handle the switching.. I would make that function of type BOOL and if they enter a invalid response then you could return false and prompt the user again with the same question... Rob Whoever said nothing's impossible never tried slamming a revolving door!
-
You could create another function to handle the switching.. I would make that function of type BOOL and if they enter a invalid response then you could return false and prompt the user again with the same question... Rob Whoever said nothing's impossible never tried slamming a revolving door!
-
Please help Here is my code. I was able to modified to go to main menu. But If user enter a value outside the range it should not go to the main menu. It should display only: cout<<"Please enter 1 or 2 (3 to exit program):"; cin>>choice; #include //using namespace std; int main(void) { int choice; float c; //Declare variable to be displayed. float f; //Question:Will it be the best practice to do this: float c=0? //Question:I used float, but I am not sure if in this case better to use int or double? for(;;) // empty to promt a user to enter correct choice value { cout<<"Please select the task to perform:"<>choice; switch (choice) { // use switch in order to do validation and calculation case 1: { cout<<"Enter value in Fahrenheit:" ; cin>>f; c=((f-32)*5/9); cout<<"The value in Centigrade is:"<>c; f=((c+32)*9/5); cout<<"The value in Fahrenheit is:"<
Your while loop is definitely testing the wrong thing. Or is there a typo? You probably need to drop the useless
for( ;; )
-loop and switch to a while-loop testing for(choice == 3)
as exit-condition. You obviously need to get the input forchoice
before this loop. As last statements in this loop (after the switch block), you need to duplicate the input for choice. That way, you will be asking forchoice
in any subsequent loops. The switch-statement will then have cases only for 1, 2, and default. Be careful what entering a letter into your float variable does! An additional hint:do
// use do-while loop
{seems to be a very silly comentary. Everyone can see this. Try not to comment what you do, but why and why exactly so and not different.
Who is 'General Failure'? And why is he reading my harddisk?!?
-
Your while loop is definitely testing the wrong thing. Or is there a typo? You probably need to drop the useless
for( ;; )
-loop and switch to a while-loop testing for(choice == 3)
as exit-condition. You obviously need to get the input forchoice
before this loop. As last statements in this loop (after the switch block), you need to duplicate the input for choice. That way, you will be asking forchoice
in any subsequent loops. The switch-statement will then have cases only for 1, 2, and default. Be careful what entering a letter into your float variable does! An additional hint:do
// use do-while loop
{seems to be a very silly comentary. Everyone can see this. Try not to comment what you do, but why and why exactly so and not different.
Who is 'General Failure'? And why is he reading my harddisk?!?
Here is my modified code. It still not going to the cout<<"Please select the task to perform:"< //using namespace std; int main(void) { int choice; float c; float f; bool enter; do { if (enter=true ) { cout<<"Please select the task to perform:"<>choice; switch (choice) { case 1: { cout<<"Enter value in Fahrenheit:" ; cin>>f; c=((f-32)*5/9); cout<<"The value in Centigrade is:"<>c; f=((c+32)*9/5); cout<<"The value in Fahrenheit is:"<
-
I didn't compile this so it may have errors.. At least I think you will get the basic idea...
BOOL OnPrompt();
int main(void)
{
//Question:Will it be the best practice to do this: float c=0?
//Question:I used float, but I am not sure if in this case better to use int or double?cout<<"Please select the task to perform:"<\>choice; switch (choice) { // use switch in order to do validation and calculation case 1: { cout<<"Enter value in Fahrenheit:" ; cin>>f; c=((f-32)\*5/9); cout<<"The value in Centigrade is:"<\>c; f=((c+32)\*9/5); cout<<"The value in Fahrenheit is:"<
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
-
Your while loop is definitely testing the wrong thing. Or is there a typo? You probably need to drop the useless
for( ;; )
-loop and switch to a while-loop testing for(choice == 3)
as exit-condition. You obviously need to get the input forchoice
before this loop. As last statements in this loop (after the switch block), you need to duplicate the input for choice. That way, you will be asking forchoice
in any subsequent loops. The switch-statement will then have cases only for 1, 2, and default. Be careful what entering a letter into your float variable does! An additional hint:do
// use do-while loop
{seems to be a very silly comentary. Everyone can see this. Try not to comment what you do, but why and why exactly so and not different.
Who is 'General Failure'? And why is he reading my harddisk?!?
Here is my updated code, but it is not doing what it should. If user enters outside the range 1,2 it should show only cout<<"Please enter 1 or 2 (3 to exit program):"; in all other cases main menu #include //using namespace std; int main(void) { int choice; float c; float f; bool enter; enter==true; do { if (enter=true ) { cout<<"Please select the task to perform:"<>choice; switch (choice) { case 1: { cout<<"Enter value in Fahrenheit:" ; cin>>f; c=((f-32)*5/9); cout<<"The value in Centigrade is:"<>c; f=((c+32)*9/5); cout<<"The value in Fahrenheit is:"<
-
I didn't compile this so it may have errors.. At least I think you will get the basic idea...
BOOL OnPrompt();
int main(void)
{
//Question:Will it be the best practice to do this: float c=0?
//Question:I used float, but I am not sure if in this case better to use int or double?cout<<"Please select the task to perform:"<\>choice; switch (choice) { // use switch in order to do validation and calculation case 1: { cout<<"Enter value in Fahrenheit:" ; cin>>f; c=((f-32)\*5/9); cout<<"The value in Centigrade is:"<\>c; f=((c+32)\*9/5); cout<<"The value in Fahrenheit is:"<
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
-
Here is my updated code, but it is not doing what it should. If user enters outside the range 1,2 it should show only cout<<"Please enter 1 or 2 (3 to exit program):"; in all other cases main menu #include //using namespace std; int main(void) { int choice; float c; float f; bool enter; enter==true; do { if (enter=true ) { cout<<"Please select the task to perform:"<>choice; switch (choice) { case 1: { cout<<"Enter value in Fahrenheit:" ; cin>>f; c=((f-32)*5/9); cout<<"The value in Centigrade is:"<>c; f=((c+32)*9/5); cout<<"The value in Fahrenheit is:"<
sardinka wrote: if (enter=true ) The compiler could have easily detected this error had it been written like:
if (true=enter)...
It's always good practice to place constants on the left of the operator and variables on the right of the operator. That way, if you ever decice to use = instead of ==, you'll receive a compiler error.
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
-
I am so sorry. But I could not compile your example. And also I did not understand :( Please explain one more time...
For brevity, Rob left out some of the basics. It was assumed you knew how to add the missing pieces. Work through the compiler/linker errors one by one until you encounter one that you just cannot figure out.
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
-
For brevity, Rob left out some of the basics. It was assumed you knew how to add the missing pieces. Work through the compiler/linker errors one by one until you encounter one that you just cannot figure out.
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
DavidCrow wrote: Five birds are sitting on a fence. Three of them decide to fly off. How many are left? I would love to guess "two", but since that's just *way* too easy, I'm gonna go with "a number". :-D The kindest thing you can do for a stupid person, and for the gene pool, is to let him expire of his own dumb choices. [Roger Wright on stupid people]
-
For brevity, Rob left out some of the basics. It was assumed you knew how to add the missing pieces. Work through the compiler/linker errors one by one until you encounter one that you just cannot figure out.
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
DavidCrow wrote: Five birds are sitting on a fence. Three of them decide to fly off. How many are left? None - if one bird takes off, so does the whole flock.
Who is 'General Failure'? And why is he reading my harddisk?!?