Thread: what is wrong with this???

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    12

    Question what is wrong with this???

    //
    // Program to convert temperature from Celsius degree
    // units into Fahrenheit degree units:
    // Fahrenheit = Celsius * (212-32)/100 +32
    //
    #include <stdio.h>
    #include <iostream.h>

    int main(int nNumberofArgs, char* pszArgs[])
    {
    int exit;
    exit = 1;
    while (exit==1)
    {
    int split;
    split = 1;
    cout << "1. Convert Celsius to Fahrenheit? \n2. Convert Fahrenheit to Celsius?\n"
    cin >> split;

    // decide which way to convert
    if (split == 1)
    {

    // enter the temerature in Celsius
    int celsius;
    cout << "Enter the Celsius temprature:\n";
    cin >> celsius;

    // calculate conversion factor for Celsius
    // to Fahrenheit
    int factor;
    factor = 212 - 32;

    // use conversion factor to convert Celsius
    // into Fahrenheit values
    int fahrenheit;
    fahrenheit = factor * celsius/100 + 32;

    // output the results
    cout << "The Fahrenheit would be:\n";
    cout << fahrenheit;
    }

    else
    {

    // enter the temerature in Fahrenheit
    int fahrenheit;
    cout << "Enter the Fahrenheit temprature:\n";
    cin >> fahrenheit;

    // calculate conversion factor for Fahrenheit
    // to Celsius
    int factor;
    factor = 212 - 32;

    // use conversion factor to convert Fahrenheit
    // into Celsius values
    int celsius;
    celsius = factor / fahrenheit * 100 - 32;

    // output the results
    cout << "The Fahrenheit would be:\n";
    cout << fahrenheit;
    }

    // quit the program or not?
    cout << "\nConvert again? \n21. yes \n2. no \n";
    cin >> exit;
    }

    return 0;
    }


    the compiler says...

    18, parse error before `>'

    i marked line 18 in bold

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    38
    It looks like you forgot the semicolon in the statement before it.
    SilasP

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    12
    oh i c thx

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    38
    Glad I could help.
    SilasP

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    12

    new problem

    //
    // Program to convert temperature from Celsius degree
    // units into Fahrenheit degree units:
    // Fahrenheit = Celsius * (212-32)/100 +32
    //
    #include <stdio.h>
    #include <iostream.h>

    int main(int nNumberofArgs, char* pszArgs[])
    {
    int exit;
    exit = 1;
    while (exit==1)
    {
    int split;
    split = 1;
    cout << "1. Convert Celsius to Fahrenheit? \n2. Convert Fahrenheit to Celsius?\n";
    cin >> split;

    // decide which way to convert
    if (split == 1)
    {

    // enter the temerature in Celsius
    int celsius;
    cout << "Enter the Celsius temprature:\n";
    cin >> celsius;

    // calculate conversion factor for Celsius
    // to Fahrenheit
    int factor;
    factor = 180;

    // use conversion factor to convert Celsius
    // into Fahrenheit values
    int fahrenheit;
    fahrenheit = factor * celsius/100 + 32;

    // output the results
    cout << "The Fahrenheit would be:\n";
    cout << fahrenheit;
    }

    else
    {

    // enter the temerature in Fahrenheit
    int fahrenheit;
    cout << "Enter the Fahrenheit temprature:\n";
    cin >> fahrenheit;

    // calculate conversion factor for Fahrenheit
    // to Celsius
    int factor;
    factor = 180;

    // use conversion factor to convert Fahrenheit
    // into Celsius values
    int celsius;
    celsius = 180/(100*(fahrenheit-32));

    // output the results
    cout << "The Celsius would be:\n";
    cout << celsius;
    }

    // quit the program or not?
    cout << "\nConvert again?\n1. yes \n2. no \n";
    cin >> exit;
    }

    return 0;
    }




    okay here is my problem now,,, every time i try to convert fahrenheit to celsius the answer is 0,,, i dont think im dealing with any decimal numbers anywhere... is it just my formula is messed up? its fine on my calculator....
    Last edited by Raian; 12-09-2001 at 09:20 PM.

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    12

    Talking weeeeeeeeeeeeeee

    nm i figured it out now it all works properly and spiffy... btw its my first program that i didnt type out the source from a book, sort of

    //
    // Program to convert temperature from Celsius degree
    // units into Fahrenheit degree units:
    // Fahrenheit = Celsius * (212-32)/100 +32
    //
    #include <stdio.h>
    #include <iostream.h>

    int main(int nNumberofArgs, char* pszArgs[])
    {
    int exit;
    exit = 1;
    while (exit==1)
    {
    int split;
    split = 1;
    cout << "1. Convert Celsius to Fahrenheit? \n2. Convert Fahrenheit to Celsius?\n";
    cin >> split;

    // decide which way to convert
    if (split == 1)
    {

    // enter the temerature in Celsius
    int celsius;
    cout << "Enter the Celsius temprature:\n";
    cin >> celsius;

    // calculate conversion factor for Celsius
    // to Fahrenheit
    int factor;
    factor = 180;

    // use conversion factor to convert Celsius
    // into Fahrenheit values
    int fahrenheit;
    fahrenheit = factor * celsius/100 + 32;

    // output the results
    cout << "The Fahrenheit would be:\n";
    cout << fahrenheit;
    }

    else
    {

    // enter the temerature in Fahrenheit
    int fahrenheit;
    cout << "Enter the Fahrenheit temprature:\n";
    cin >> fahrenheit;

    // calculate conversion factor for Fahrenheit
    // to Celsius
    int factor;
    factor = 180;

    // use conversion factor to convert Fahrenheit
    // into Celsius values
    int celsius;
    celsius = 100*(fahrenheit-32)/180;

    // output the results
    cout << "The Celsius would be:\n";
    cout << celsius;
    }

    // quit the program or not?
    cout << "\nConvert again?\n1. yes \n2. no \n";
    cin >> exit;
    }

    return 0;
    }

  7. #7
    Registered User
    Join Date
    Dec 2001
    Posts
    38
    I think something might be wrong with the formula. You've declared celsius as int type. When you plug in a value into the formula, it's gonna get a little weird. Say you plug in 32 for the fahrenheit degrees, you'll get an error because division by zero is undefined. If you plug in 33 for the degrees, you will get 1.8. If you input 34 degrees, you get 180/200 which is .9 , see what I mean. Check the formula.
    SilasP

  8. #8
    Registered User
    Join Date
    Dec 2001
    Posts
    12

    ???

    so instead of making them int, they should be float?

  9. #9
    Registered User
    Join Date
    Dec 2001
    Posts
    38
    Try double. It covers any that comes out as decimals. If it's declared int, the first whole number is the result. Ex. 0.5 would be 0, or 1.4 would be 1.
    SilasP

  10. #10
    Registered User
    Join Date
    Dec 2001
    Posts
    12
    saaa weet ,,, float does the trick i think

    //
    // Program to convert temperature from Celsius degree
    // units into Fahrenheit degree units:
    // Fahrenheit = Celsius * (212-32)/100 +32
    //
    #include <stdio.h>
    #include <iostream.h>

    int main(int nNumberofArgs, char* pszArgs[])
    {
    int exit;
    exit = 1;
    while (exit==1)
    {
    int split;
    split = 1;
    cout << "1. Convert Celsius to Fahrenheit? \n2. Convert Fahrenheit to Celsius?\n";
    cin >> split;

    // decide which way to convert
    if (split == 1)
    {

    // enter the temerature in Celsius
    float celsius;
    cout << "Enter the Celsius temprature:\n";
    cin >> celsius;

    // calculate conversion factor for Celsius
    // to Fahrenheit
    float factor;
    factor = 180;

    // use conversion factor to convert Celsius
    // into Fahrenheit values
    float fahrenheit;
    fahrenheit = factor * celsius/100 + 32;

    // output the results
    cout << "The Fahrenheit would be:\n";
    cout << fahrenheit;
    }

    else
    {

    // enter the temerature in Fahrenheit
    float fahrenheit;
    cout << "Enter the Fahrenheit temprature:\n";
    cin >> fahrenheit;

    // calculate conversion factor for Fahrenheit
    // to Celsius
    float factor;
    factor = 180;

    // use conversion factor to convert Fahrenheit
    // into Celsius values
    float celsius;
    celsius = 100*(fahrenheit-32)/180;

    // output the results
    cout << "The Celsius would be:\n";
    cout << celsius;
    }

    // quit the program or not?
    cout << "\nConvert again?\n1. yes \n2. no \n";
    cin >> exit;
    }

    return 0;
    }

  11. #11
    Registered User
    Join Date
    Dec 2001
    Posts
    12
    ok ic double = better

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM