Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Temperature conversion

Reply
Thread Tools

Temperature conversion

 
 
deanfamily11
Guest
Posts: n/a
 
      09-10-2005
I'm trying to have this program do a simple temperature conversion from
Fahrenheit to Celsius. I have confirmed that the other variable is
receiving and calculating the conversion, but it is just outputting as "0".
Any thoughts? (Code is below)


#include <iostream>
#include <iomanip>
using namespace std;

int main()
{

//declare variable
int fahre;
double centi;

//get the temperature
cout << "Welcome to the temperature converter." << endl << endl;
cout << "Enter a temperature in degrees Fahrenheit: ";
cin >> fahre;
cout << endl;
cout << endl;
cout << endl;

//convert the temperature to centigrade
centi = (fahre - 32) * (5 / 9);

//output both the original temperature and the converted one
cout << "Below is your original and converted temperatures." << endl;
cout << "Degrees F: " << fahre << endl;
cout << "Degrees C: " << centi << endl;

return 0;
}


 
Reply With Quote
 
 
 
 
Shezan Baig
Guest
Posts: n/a
 
      09-10-2005
deanfamily11 wrote:
> I'm trying to have this program do a simple temperature conversion from
> Fahrenheit to Celsius. I have confirmed that the other variable is
> receiving and calculating the conversion, but it is just outputting as "0".
> Any thoughts? (Code is below)
>
> [snip]
>
> //convert the temperature to centigrade
> centi = (fahre - 32) * (5 / 9);



Change "(5 / 9)" to "(5.0 / 9.0)". When you do 5/9, it uses integer
arithmetic, so the result becomes 0. So you are essentially doing
"(fahre - 32) * 0"

Hope this helps,
-shez-

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PSD to XHTML Conversion Services and PSD to HTML CSS ConversionServices, PSD to Joomla, Drupal, Wordpress Conversion xhtml champs Python 0 06-21-2011 11:59 AM
PSD to XHTML Conversion Services and PSD to HTML CSS ConversionServices, PSD to Joomla, Drupal, Wordpress Conversion PSD to XHTML Conversion Services and PSD to HTML CSS Conversion Services, PSD to Joomla, Drupal, Wor VHDL 0 04-25-2011 06:43 AM
conversion operator and conversion ctor subramanian100in@yahoo.com, India C++ 2 09-15-2009 12:46 PM
Temperature Conversion Program - Still a Rookie AsheeG87@msn.com C++ 21 04-03-2007 12:43 AM
a temperature conversion programme arnuld C++ 4 03-04-2007 10:13 AM



Advertisments