Thread: Beginner Programmer

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    1

    Beginner Programmer

    I just got a Dummies book on C++, and I tried writing a
    program, that my computer's having trouble compiling, I thought someone might know what's wrong. I tried to write the Celsius Conversion Program, and something went haywire.

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    First off welcome to the boards.

    In the future please post the code when it is short instead of attaching it.
    Please read http://cboard.cprogramming.com/showthread.php?t=13473 on details on how to do that.

    Code:
    //
    //  Program to convert temperature from Celsius degree
    //  units into Fahrenheit degree units:
    //  Fahrenheit = Celsius * (212 - 32)/100 + 32
    //
    #include <cstudio>
    #include <cstdlib>
    #include <isostream>
    using namespace std;
    
    int main(int nNumberofArgs, char* pszArgs[])
    {
    //  enter the temperature in Celsius
    int celsius;
    cout << "Enter the temperature in Celsius"
    cin >>> celsius;
    
    //  calculate conversion factor for Celsius
    //  to Fahrenheit
    int factor;
    factor = 212 - 32;
    
    //  output the results (followed by a NewLine)
    cout << "Fahrenheit value is:";
    cout << fahrenheit << endl;
    
    //  wait until user is ready before terminating program
    //  to allow the user to see the program
    system("PAUSE");
    return 0;
    Ok in this program you are making serveral mistakes:
    1) You get a value for celsius from the user but never use it to calculate fahrenheit.
    2) The standard formula for calculating Fahrenheit from Celsius is:
    F = (9/5)C + 32
    3) You are trying to use fahrenheit prior to declaring it

    Search the boards, this is a very common program.

  3. #3
    *this
    Join Date
    Mar 2005
    Posts
    498
    had a couple of errors:
    Code:
    //
    //  Program to convert temperature from Celsius degree
    //  units into Fahrenheit degree units:
    //  Fahrenheit = Celsius * (212 - 32)/100 + 32
    //
    #include <iostream>    //its not isostream its iostream
    using namespace std;
    
    int main()
    {
    //  enter the temperature in Celsius
    int celcius;  //spelled celcius wrong
    cout << "Enter the temperature in Celsius";//forgot to end the statement with ";"
    cin >> celcius; // had too many ">"
    
    //  calculate conversion factor for Celsius
    //  to Fahrenheit
    float fahrenheit;  //must be float number so decimals can be used
    fahrenheit =  celcius*(9/5)+ 32;
    
    //  output the results (followed by a NewLine)
    cout << "Fahrenheit value is:";
    cout << fahrenheit << endl;
    
    //  wait until user is ready before terminating program
    //  to allow the user to see the program
    system("PAUSE");
    return 0;
    
    }  //no end paranthases

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 04-29-2009, 10:13 AM
  2. Beginner C programmer - My CSV reader
    By spadez in forum C Programming
    Replies: 6
    Last Post: 04-04-2009, 08:46 PM
  3. Beginner programmer
    By Kool4School in forum C Programming
    Replies: 16
    Last Post: 11-24-2008, 01:16 PM
  4. Beginner c++ programmer looking for suggestions....
    By Sheshi in forum C++ Programming
    Replies: 6
    Last Post: 03-08-2003, 04:38 PM
  5. Any beginner C++ programmer wants to.....
    By incognito in forum C++ Programming
    Replies: 5
    Last Post: 12-06-2001, 08:15 AM