Thread: Help with almost solved problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by Kaname View Post
    I am a newbie when it come to C++ but I think I am close to solving this code. Can anyone tell me where my mistake is. I am having on the Temperature reading.

    Code:
    #include<stdio.h>
    
    iint choice; /* 1 to convert celsius, 2 to convert fahrenheit. //
        int c; // degrees in celsius//
        int f; // degrees in fahrenheit//
        float ctemp, ftemp; //temperatures//
    
    int main ( void )
    
    {
        printf( "This program converts from celsius to fahrenheit and fahrenheit to celsius.\n" );
    
        printf( "Enter 1 for Fahrenheit to Celsius or 2 for Celsius to Farenheit.\n" );
    
        scanf("%d", &choice); //input from user//
    
    if (choice == 1)
    {
        printf( "Enter degrees in Fahrenheit.");
        scanf ("%d", &f); 
        ctemp = (5/9) * (f-32);
        printf ( "Temperature in Celsius is", ctemp); //Degrees in celsius//
    }
    else{ 
        if (choice == 2)
        {
        printf( "Enter degrees in Celsius.");
        scanf ("%d", &c); //get degrees celsius from user//
        ftemp = (9/5) * (c+32);
        printf ( "Temperature in farenheit is", ftemp); //output degrees in celsius//
        }
        else 
        printf ( "Bad selection." );
    }
    
    return 0; //end program//
    }
    There are a whole lot of things to be pointed out in your code-
    1. This is not a C++ code, it's perfectly C, so you posted in a wrong section.
    2. There is nothing called "iint" in C.
    3. Comment your code properly. If you've started with /* so you should end up with */ not //. // is a single line comment used with one lines only. For eg. here is a single line comment:
    int i; //this is a comment
    4. As tabstop mentioned change 5/9 and 9/5 to 5.0/9 and 9.0/5.
    5. Use proper format specifier to print the required value. eg %f in you case.
    6. It would be better not to make global declarations for all the variables.
    Last edited by BEN10; 09-12-2009 at 06:59 AM.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  2. A confusing problem with my linked list
    By edd1986 in forum C++ Programming
    Replies: 0
    Last Post: 03-19-2006, 10:33 AM
  3. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  4. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  5. binary tree problem - help needed
    By sanju in forum C Programming
    Replies: 4
    Last Post: 10-16-2002, 05:18 AM

Tags for this Thread