In: Computer Science
Assignment 2 is on page 146, question 12. The assignment asks you to write a program to allow a user to enter a temperature in Celsius and convert it to Fahrenheit. Then display the new temperature on the screen. Consider using the fixed, showpoint, and setprecision stream manipulators with your output. (hint, probably points to what sort of numeric variables you should use) The formula to convert from C to F is in the book on page 146.
For extra credit, have your program then ask for the temperature in Fahrenheit and convert to Celsius and display in a similar manner.
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
float fahrenheit, celsius,fahrenheit_2,celsius_2;
cout << "Enter the temperature in Celsius : ";
cin >> celsius;
fahrenheit = (celsius * 9.0) / 5.0 + 32;
cout << "The temperature in Celsius : " <<celsius
<< endl;
cout << "The temperature in Fahrenheit : "
<<fixed<<setprecision(2)<< fahrenheit <<
endl;
// for extra credit
cout << "Enter the temperature in Farenheit : ";
cin>>fahrenheit_2;
celsius_2=(fahrenheit_2-32)*5/9;
cout << "The temperature in Fahrenheit : "
<<fahrenheit_2 << endl;
cout << "The temperature in Celsius : "
<<fixed<<setprecision(2)<< celsius_2 <<
endl;
return 0;
}