Thank you very much I got it.
Helpful.
Edit: I don't know if I should start a new topic for this second code I'm working on.
It converts C to F temperatures
and Miles to KM temperatures.
It works perfectly I used a loop within a loop to have a selection between Temp and Distance. Then whether to convert F to C, or C to F. Km to M or M to KM.
Although it works functionally here's what it's doing that's a tad bit annoying. If you press 3, it will exit the screen and return to the previous one but it'll output the message "You have not enterered 1 2 or 3." so although it works properly, it outputs that message for some reason.
Try it for yourself, press 1 to enter Temperatures, then press 3 to return to previous screen. You'll see it works, but with the message showing up.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
#include <cstdlib>
#include <iostream>
using namespace std;
int CtoF()
{
float temp;
cout << "\n Please enter the temperature in Celcius \n";
cin >> temp;
cout << temp << " Degress Celcius is " << (temp * 1.8) +32 << " Degress Fahrenheit. \n \n";
return 0;
}
int FtoC()
{
float temp;
cout << "\n Please enter the temperature in Fahrenheit \n";
cin >> temp;
cout << temp << " Degress Fahrenheit is " << (temp - 32) /1.8 << " Degress Celcius. \n \n";
return 0;
}
int MtoKM()
{
float distance;
cout << "\n Please enter the distance in Miles \n";
cin >> distance;
cout << distance << " Miles is " << (distance / 0.621371) << " KM. \n \n";
return 0;
}
int KMtoM()
{
float distance;
cout << "\n Please enter the distance in KM \n";
cin >> distance;
cout << distance << " KM is " << (distance * 0.621371) << " Miles. \n \n";
return 0;
}
int main(int argc, char *argv[])
{
int option;
int option2;
int option3;
do
{
cout << "[Feel Goods Unit Converter.] \n";
cout << "Please Type 1 to convert Temperatures, Please Type 2 to convert Distances. \n";
cout << "Type 3 when you are finished to exit. \n \n";
cin >> option;
if (option == 1)
{
do
{
cout << "Please type 1 to convert C to F, and type 2 to convert F to C. \n";
cout << "Please type 3 to go back to main menu. \n";
cin >> option2;
if (option2 == 1)
{
CtoF();
}
else if (option2 == 2)
{
FtoC();
}
else if (option !=3)
{
cout << "\n You have not chosen 1, 2, or 3, please enter a correct number. \n \n";
} }while(option2 !=3);
}
else if ( option == 2 )
do
{
cout << " Please enter 1 to convert Miles to KM. Please enter 2 to convert KM to Miles. \n";
cout << " Please enter 3 to return to the main menu. \n";
cin >> option3;
if( option3 == 1)
{
MtoKM();
}
else if (option3 == 2)
{
KMtoM();
}
else if (option !=3)
{
cout << "\n You have not chosen 1, 2, or 3, please enter a correct number. \n \n";
}} while(option3 !=3);
else if (option !=3)
{
cout << "\n You have not chosen 1, 2, or 3, please enter a correct number. \n \n";
}
} while(option != 3);
return 0;
}
|