temperature help

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Feb 2006
Posts: 23
Reputation: jlouang is an unknown quantity at this point 
Solved Threads: 1
jlouang jlouang is offline Offline
Newbie Poster

temperature help

 
0
  #1
May 4th, 2006
can someone help me i can't seem to find my temperature problem



  1. /****************************
  2. * functions
  3. *****************************/
  4. float c2F(float);
  5. float f2C(float);
  6.  
  7. /****************************
  8. * gloabal variables
  9. *****************************/
  10.  
  11. int main ()
  12. {
  13. float inTemp;
  14. float newTemp;
  15. char inCode;
  16.  
  17. cout << "please enter the code (a 'C' of 'F'): ";
  18. cin >> inCode;
  19.  
  20. cout << "please enter the tempature to be converted: ";
  21. cin >> inTemp;
  22.  
  23. if (inCode == 'C')
  24. {
  25. newTemp = c2F(inTemp);
  26. cout << "converted temp is " << newTemp << "\n";
  27. }
  28. else if (inCode == 'F')
  29. {
  30. newTemp = f2C(inTemp);
  31. cout << "converted temp is " << newTemp << "\n";
  32. }
  33. else
  34. {
  35. newTemp = 0;
  36. cout << "bad code entered\n";
  37. }
  38.  
  39. system("pause");
  40.  
  41. return 0;
  42. }
  43. /****************************
  44. * converts a temp from F->C using the formula F=5/9(C-32)
  45. *****************************/
  46. float f2C (float inTemp)
  47. {
  48. float newTemp = 5/9* (inTemp-32);
  49. return newTemp;
  50. }
  51. /****************************
  52. * converts a temp from C->F the formula C=9/9(F) +32
  53. *****************************/
  54. float c2F (float inTemp)
  55. {
  56. float newTemp = 9/5* inTemp+32;
  57. return newTemp;
  58. }
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 54
Reputation: HackWizz is an unknown quantity at this point 
Solved Threads: 2
HackWizz HackWizz is offline Offline
Junior Poster in Training

Re: temperature help

 
0
  #2
May 4th, 2006
What is the problem ..specify that..and put brackets in the formula to avoid confusion and miscalculation
return 0;
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 23
Reputation: jlouang is an unknown quantity at this point 
Solved Threads: 1
jlouang jlouang is offline Offline
Newbie Poster

Re: temperature help

 
0
  #3
May 4th, 2006
i updated the my code up there again and like when I run it the answer turns out wrong
  1. /****************************
  2. * functions
  3. *****************************/
  4. float c2F(float);
  5. float f2C(float);
  6.  
  7. /****************************
  8. * gloabal variables
  9. *****************************/
  10.  
  11. int main ()
  12. {
  13. float inTemp;
  14. float newTemp;
  15. char inCode;
  16.  
  17. cout << "please enter the code (a 'C' of 'F'): ";
  18. cin >> inCode;
  19.  
  20. cout << "please enter the tempature to be converted: ";
  21. cin >> inTemp;
  22.  
  23. if (inCode == 'C')
  24. {
  25. newTemp = c2F(inTemp);
  26. cout << "converted temp is " << newTemp << "\n";
  27. }
  28. else if (inCode == 'F')
  29. {
  30. newTemp = f2C(inTemp);
  31. cout << "converted temp is " << newTemp << "\n";
  32. }
  33. else
  34. {
  35. newTemp = 0;
  36. cout << "bad code entered\n";
  37. }
  38.  
  39. system("pause");
  40.  
  41. return 0;
  42. }
  43. /****************************
  44. * converts a temp from F->C using the formula F=5/9(C-32)
  45. *****************************/
  46. float f2C (float inTemp)
  47. {
  48. float newTemp = 5/9* (inTemp-32);
  49. return newTemp;
  50. }
  51. /****************************
  52. * converts a temp from C->F the formula C=9/9(F) +32
  53. *****************************/
  54. float c2F (float inTemp)
  55. {
  56. float newTemp = 9/5* inTemp+32;
  57. return newTemp;
  58. }
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,416
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 248
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: temperature help

 
0
  #4
May 4th, 2006
With integer math 9/5 is 1 and 5/9 is zero. Try 9.0/5.0 and 5.0/9.0.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 23
Reputation: jlouang is an unknown quantity at this point 
Solved Threads: 1
jlouang jlouang is offline Offline
Newbie Poster

Re: temperature help

 
0
  #5
May 4th, 2006
thanks I figure out that I was trying to divide a int by a float which wouldn't work of course. changing it to 9.0 and 5.0 works
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC