Thread: Help with C++ Program

  1. #1
    Registered User
    Join Date
    Sep 2010

    Help with C++ Program

    This code is supposed to calculate and print out the temperature where the temperature in celsius is the same in Fahrenheit. So it should print -40 but instead it prints nothing. Please help.

    using namespace std;
    int main()
    {int celsius=100, fahrenheit;
    do {
    cout<<"Celsius and fahrenheit are the same at "<<fahrenheit;
    return 0;

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    New Zealand
    9/5 is 1 in C++
    You should reorganise that expression so that the multiplication is executed before the division
    That's horrible formatting btw, never put the closing brace on the end of a line of code.
    Add some whitespace too.
    Check the FAQ for why your console disappears so quickly.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #3
    Join Date
    Oct 2007
    Inside my computer
    Indent, format. 9/5 is integer divsision; thus it yields one. If you do 9.0/5, you should see that you'll get some different answers.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    United States
    Hmm, and then after you convert to floating point there is the issue of floating point equality.

    abs( fahrenheit - celsius ) < 0.0001

    Or however close you want to be, but not exact.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM