I spent 2 days of trying something this is what i came up with, but i am still stuck on the choice parts. am i doing it right? this is what i did.
QUESTION
Write a program that repeatedly ask the user to choose one of the choices:
1. Choice 1 : Convert Fahrenheit to Celsius using the formula :
°F = °C x 9/5 + 32
2. Choice 2: Convert Celsius to Fahrenheit using the formula :
°C = (°F - 32) x 5/9
3. Choice 3: Exit the Program
The program should read the user input and then display the result or an error message as appropriate, a sample program run is provided below:
Sample run:
Welcome to the Temperature Converter Application
Please type 1 for Fahrenheit to Celsius conversion
Type 2 for Celsius to Fahrenheit conversion.
Or type -1 to exit the program
1
Please enter your temperature in Fahrenheit
86
Computing...
The temperature in Celsius is 30
Please type 1 for Fahrenheit to Celsius conversion
Type 2 for Celsius to Fahrenheit conversion.
Or type -1 to exit the program
5
That is not an option.
Please type 1 for Fahrenheit to Celsius conversion
Type 2 for Celsius to Fahrenheit conversion.
Or type -1 to exit the program
2
Please enter your temperature in Celsius
20
Computing...
The temperature in Fahrenheit is 68
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
|
#include <iostream>
using namespace std;
int main()
{
float celsius;
float fahrenheit;
cout<<"Choose on of the choices"<<endl;
cout<<"1. Convert Fahrenheit to Celsius"<<endl;
cout<<"2. Convert Celsius to Fahrenheit"<<endl;
cout<<"3. Exit the Program"<<endl;
cout << "Enter Celsius temperature: ";
cin >> celsius;
fahrenheit = (celsius * 9.0) / 5.0 + 32;
cout << "Fahrenheit = " << fahrenheit << endl;
cout << "Enter Fahrenheit temperature: ";
cin >> fahrenheit;
celsius = (fahrenheit - 32) * 5/9;
cout << "Celsius = " << celsius << endl;
system("PAUSE");
return 0;
}
|