Celcius

This is a discussion on Celcius within the C++ Programming forums, part of the General Programming Boards category; Im trying to compile a program for a book heres my code Code: #include <cstdio> #include <cstdlib> #include <iostream> using ...

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    8

    Celcius

    Im trying to compile a program for a book
    heres my code
    Code:
    #include <cstdio>
    #include <cstdlib>
    #include <iostream>
    using namespace std;
    
    int main(int nNumberofArgs, char* pszArgz[])
    {
    int celsius;
    cout <<"Enter The Temperture in Celcius:";
    cin >> celsius;
    
    int factor;
    factor - 212 - 32; 
    int fahrenhiet; 
    fahrenhiet - factor * celsius/100 + 32;
    cout <<"Fahrenhiet value is:";
    cout << fahrenhiet << endl;
    system("pause");
    return 0;
    }
    It complies and opens fine but it dosen't work it seems that the math is wrong. If i type in 0 Celcius i get 4198592
    HELP!!!!!!!!

  2. #2
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Location
    Mt. Prospect, IL
    Posts
    2,572
    what are the errors?

    this should be one: factor - 212 - 32
    also initialize yourvars to 0, or something else. Factor should probably be a fraction, I forget what it is; 4/9 or something like that, and it should be stored in a double or a float; same with fahrenhiet.

    this should be another error: fahrenhiet - factor * celsius/100 + 32;
    I believe you want :fahrenhiet = factor * celsius/100 + 32;

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  3. #3
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    You never initialize or assign to your variables.
    Both lines:
    Code:
    factor - 212 - 32;
    ...
    fahrenhiet - factor * celsius/100 + 32;
    Do nothing. Perhaps those first '-'s ought to be '='.

    It will also be wrong because you are using integer arithmetic and not floating point arithmetic.

    [ edit ] Rats! Beaten. [ /edit ]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pass by reference
    By mcgeady in forum C Programming
    Replies: 11
    Last Post: 02-17-2005, 02:01 AM
  2. need help with homework code
    By acidbeat311 in forum C Programming
    Replies: 2
    Last Post: 02-15-2005, 09:43 PM
  3. sorry to bother all but please help me :)
    By cam123666 in forum C++ Programming
    Replies: 5
    Last Post: 02-04-2005, 06:24 PM
  4. Need help with a temperature c prog, thanks
    By McFury in forum C Programming
    Replies: 9
    Last Post: 05-26-2004, 01:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21