Connecting Tech Pros Worldwide Forums | Help | Site Map

Logical error in program to convert celsius to farenheit.

Newbie
 
Join Date: Sep 2007
Posts: 11
#1: Sep 11 '07
Hi i was wondering why the hell this program isn't working for me, I am in a 100 level computer science class and need help. This program is supposed to take in data of degrees Fahrenheit and spit out what it is in Celsius, anyway here it is and tell me if there is anything wrong:


Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.    double temperatureF;
  7.  
  8.    cout << "Type the temperature in degrees Fahrenheit ->  ";
  9.  
  10.    double temperatureF;
  11.    cin << temperatureF;
  12.  
  13.    double temperatureC;  
  14.    temperatureC=(temperatureF-32)*(5/9);
  15.    cout << temperatureF "degrees Fahrenheit is equal to " << temperatureC << "          degrees celsius." << endl;
  16.    return 0;
  17. }

gpraghuram's Avatar
Expert
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,258
#2: Sep 11 '07

re: Logical error in program to convert celsius to farenheit.


Quote:

Originally Posted by kipj77

Hi i was wondering why the hell this program isn't working for me, I am in a 100 level computer science class and need help. This program is supposed to take in data of degrees Fahrenheit and spit out what it is in Celsius, anyway here it is and tell me if there is anything wrong:



#include <iostream>
using namespace std;

int main()
{
double temperatureF;

cout << "Type the temperature in degrees Fahrenheit -> ";

double temperatureF;
cin << temperatureF;

double temperatureC;
temperatureC=(temperatureF-32)*(5/9);
cout << temperatureF "degrees Fahrenheit is equal to " << temperatureC << " degrees celsius." << endl;
return 0;
}

Hi,
Please check thi.
I have made some changes in the code
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. double temperatureF;
  7.  
  8. cout << "Type the temperature in degrees Fahrenheit -> ";
  9.  
  10. //double temperatureF;
  11. cin>>temperatureF;
  12.  
  13. double temperatureC; 
  14. temperatureC=(temperatureF-32)*(5/9.0);
  15. cout << temperatureF <<"degrees Fahrenheit is equal to " << temperatureC << " degrees celsius." << endl;
  16. return 0;
  17. }
  18.  
NOTE:Please use code tags for submitting any code

Thanks
Raghuram
dmjpro's Avatar
Lives Here
 
Join Date: Jan 2007
Location: India (West-Bengal)
Posts: 2,451
#3: Sep 11 '07

re: Logical error in program to convert celsius to farenheit.


Quote:

Originally Posted by kipj77

Hi i was wondering why the hell this program isn't working for me, I am in a 100 level computer science class and need help. This program is supposed to take in data of degrees Fahrenheit and spit out what it is in Celsius, anyway here it is and tell me if there is anything wrong:


Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.    double temperatureF;
  7.  
  8.    cout << "Type the temperature in degrees Fahrenheit ->  ";
  9.  
  10.    double temperatureF;
  11.    cin << temperatureF;
  12.  
  13.    double temperatureC;  
  14.    temperatureC=(temperatureF-32)*(5/9);
  15.    cout << temperatureF "degrees Fahrenheit is equal to " << temperatureC << "          degrees celsius." << endl;
  16.    return 0;
  17. }

Welcome to TSDN.
Use Code Tags while you do Post according to Posting Guidelines.
gpraghuram is right.
(5/9) will lead to a Integer value that's why your result is showing error.
Good luck with you try.

Kind regards,
Dmjpro.
Newbie
 
Join Date: Sep 2008
Posts: 1
#4: Sep 22 '08

re: Logical error in program to convert celsius to farenheit.


Guys,

Check out all c++ programs at www.citysuvidha.com.You will find all samlple programs in c and c++ programming language for free.

www.citysuvidha.com/Blogs
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#5: Sep 22 '08

re: Logical error in program to convert celsius to farenheit.


Quote:

Originally Posted by citysuvidha

Guys,

Check out all c++ programs at www.citysuvidha.com.You will find all samlple programs in c and c++ programming language for free.

www.citysuvidha.com/Blogs

Offfering such a service breeds stupid people; also, all those C and C++ programs
of yours suck big times, i.e. they all violate the Standards; better get them offline
asap. I think you don't want to be associated with that crap.

kind regards,

Jos (moderator)
Reply