473,386 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Logical error in program to convert celsius to farenheit.

11
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. }
Sep 11 '07 #1
4 3607
gpraghuram
1,275 Expert 1GB
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
Sep 11 '07 #2
dmjpro
2,476 2GB
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.
Sep 11 '07 #3
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
Sep 22 '08 #4
JosAH
11,448 Expert 8TB
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)
Sep 22 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Lazareth S. Link | last post by:
Hiya to whoever might stumble across this. I've recently taken up learning how to script/program in python. I've made my first program, a simple fahrenheit-celsius converter, both ways. For...
4
by: muser | last post by:
Can anyone run this program through their compiler or if they can see a logical error please point it out. I have my tutor working on it at the moment but I would rather a less ambigious response...
6
by: Andrew Banks | last post by:
I'm trying a simple application and keep getting the following debug information when I try and run the application. The console window simply opens then closes in an instant. Does anyone have...
2
by: ff2 | last post by:
Ok i'm using Borland CBX and Windows XP. My program is to convert farenheit to celsius. I got the code off the CD that came with "Sams Teach Yourself C++ in 24 Hours" so i doubt the code is wrong. I...
1
by: Jay204 | last post by:
i have a simple program im making with basic knowledge of java its supposed to prompt for a celsius temperature do the calculation to convert it to fahrenhiet then pop up saying the result ...
1
by: Raghuram N K | last post by:
Hi, Following program compiles and executes successfully in windows with DevCPP compiler. When I compile the same in Linux with 'g++323' compiler I get following assignment error: cannot...
21
by: AsheeG87 | last post by:
Hey Everyone~ I'm still a C++ Rookie so please bear with me on this. I'm doing a temperature conversion program with prototype functions. Basicly, I was wondering if some of you would take a look...
11
by: icarus | last post by:
Hi, this is a simple temperature converter (Fahrenheit to Celsius to Kelvin). Using gcc 4.0. The user is supposed to enter q or any other non-character to exit the program. Problem with this...
3
by: jmf777 | last post by:
Hi here is the problem when my program tries to convert Fahrenheit to Celsius it gives an answer of zero regardless of what degree you put in. Any help in solving this is much appreciated. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.