Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
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
Comments
Ian A Davidson at 6-May-13 4:51am
   
Sounds like homework to me. Have you tried anything yourself yet?
Jopa Tidman at 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: bad
good
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!
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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

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

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 120
4 DamithSL 95
0 OriginalGriff 6,045
1 DamithSL 4,611
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 6 May 2013
Copyright © CodeProject, 1999-2014
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