12,072,809 members (72,352 online)
Rate this:
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 23: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
#include
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:

## 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:

## 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)

Top Experts
Last 24hrsThis month
 OriginalGriff 465 Dave Kreskowiak 275 CPallini 255 F-ES Sitecore 220 Jochen Arndt 150
 Dave Kreskowiak 2,506 OriginalGriff 2,034 Richard MacCutchan 1,675 CPallini 1,377 CHill60 1,219

Advertise | Privacy | Mobile
Web01 | 2.8.160208.1 | Last Updated 6 May 2013