Click here to Skip to main content
13,052,494 members (77,338 online)
Rate this:
Please Sign up or sign in to 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 5-May-13 22:50pm
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;
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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!
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

What about reading the documentation (showpos[^], setprecision[^])?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 6 May 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100