![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5
![]() |
Here is another that I did, but there is a little bug which won’t take you more than less minute to fix it:
When user selects 0 I want to exit…. Where is my mistake? #include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int option,number;
double result;
// menu option
cout << "Program to convert from Inches, feet and yards to meters" <<endl;
cout << "--------------------------------------------------------" <<endl;
cout << "Enter 1 to convert from Inches to meters" <<endl;
cout << "----------------------------------------" <<endl;
cout << "Enter 2 to convert from feet to meters" <<endl;
cout << "----------------------------------------" <<endl;
cout << "Enter 3 to convert from inch to meters" <<endl;
cout << "----------------------------------------" <<endl;
cout << "Enter 0 to exit" << endl;
cout << "****************************************" <<endl;
cin >> option;
//end here
// select kind of calc
cout << "Enter the length" <<endl;
cout << "----------------" <<endl;
cin >> number;
//start calc here
switch (option)
{
case 0:
return (0);
case 1:
result = ( number * 0.9144 );
break;
case 2:
result = ( number * 0.3048 );
break;
case 3:
result = ( number * 0.0254 );
break;
}
cout << "The result of the converstion is: " << result <<endl;
system("PAUSE");
return 0;
__________________
Personal Portfolio TecBrain Support Forum Linux VS Windows ... Dont Even Think of it .. Distribution: Slackware if (OS==Linux) return success There are 10 kinds of people, those who can read binary numbers and those who can't. |
|
|
|
|
|
#2 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
You need to put the switch before you input number.
Edit: Actually, that would cause a problem, because you would be performing all the calculations before you enter number. Instead of testing for 0 in the switch, take it out and put an if statement before you enter number to test for 0. Leave the switch statement where you originally had it.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5
![]() |
Well everything works correctly except the case 0 part.
__________________
Personal Portfolio TecBrain Support Forum Linux VS Windows ... Dont Even Think of it .. Distribution: Slackware if (OS==Linux) return success There are 10 kinds of people, those who can read binary numbers and those who can't. |
|
|
|
|
|
#4 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
Check the edit. That should do it.
![]()
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5
![]() |
Perfect.
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int option,number;
double result;
// menu option
cout << "Program to convert from Inches, feet and yards to meters" <<endl;
cout << "--------------------------------------------------------" <<endl;
cout << "Enter 1 to convert from Inches to meters" <<endl;
cout << "----------------------------------------" <<endl;
cout << "Enter 2 to convert from feet to meters" <<endl;
cout << "----------------------------------------" <<endl;
cout << "Enter 3 to convert from inch to meters" <<endl;
cout << "----------------------------------------" <<endl;
cout << "Enter 0 to exit" << endl;
cout << "****************************************" <<endl;
cin >> option;
//end here
// select kind of calc
cout << "Enter the length" <<endl;
cout << "----------------" <<endl;
if (option == 0 )return (0);
cin >> number;
//start calc here
switch (option)
{
case 1:
result = ( number * 0.9144 );
break;
case 2:
result = ( number * 0.3048 );
break;
case 3:
result = ( number * 0.0254 );
break;
}
cout << "The result of the converstion is: " << result <<endl;
system("PAUSE");
return 0;
}Thanks....
__________________
Personal Portfolio TecBrain Support Forum Linux VS Windows ... Dont Even Think of it .. Distribution: Slackware if (OS==Linux) return success There are 10 kinds of people, those who can read binary numbers and those who can't. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|