Click here to Skip to main content
15,885,079 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Could someone help solve this c++ problem which is based on stream input/output..

Write a program that converts integer Fahrenheit temperatures from 0 to 212 degrees to floatingpoint
Celsius temperatures with 3 digits of precision. Use the formula
celsius = 5.0 / 9.0 * ( fahrenheit - 32 );
to perform the calculation. The output should be printed in two right justified columns and the
Celsius temperatures should be preceded by a sign for both positive and negative values...


Your help will be greatly appreciated.
Posted
Comments
Ian A Davidson 6-May-13 4:51am    
Sounds like homework to me. Have you tried anything yourself yet?
Jopa Tidman 6-May-13 6:25am    
Yes, just trying to confirm my answer. Here's my solution code..

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float cel = 0;
cout << setprecision(1) << fixed; //sets 1 decimal place (fixed makes it decimals instead of digits)
cout << "Fahrenheit\tCelsius" << endl;
for( int i = 0; i <= 212; i += 1)
{
cel = (5.0/9.0)*double(i-32);//calculation happens here.
cout << i << "\t" << cel << endl;
}
system ("pause");
return 0;
}

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!
 
Share this answer
 
What about reading the documentation (showpos[^], setprecision[^])?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900