Thread: help me plz to Solve this Question.

  1. #1
    Registered User
    Join Date
    Oct 2013
    Posts
    6

    Post help me plz to Solve this Question.

    Problem Statement:

    You are required to write a simple “Temperature Conversion Calculator” using C++ language. The objective of this program should be to convert one temperature unit to other temperature units. These temperature units are Fahrenheit, Celsius and Kelvin etc.

    Detailed Description:

    The program should prompt the user to enter his/her option.

    The program should respond in the following ways using switch statement:

    1. If user enters option ‘F’ or ‘f’ then it should prompt the user to enter temperature in Fahrenheit. It should then convert it into Celsius and Kelvin and display the values on the screen.

    2. If user enters option ‘C’ or ‘c’ then it should prompt the user to enter temperature in Celsius. It should then convert it into Fahrenheit and Kelvin and display the values on the screen.

    3. If user enters option ‘K’ or ‘k’ then it should prompt the user to enter temperature in Kelvin. It should then convert it into Celsius and Fahrenheit and display the values on the screen.

    After performing conversion operation, it should ask the user to continue or not. If user enters ‘n’ then it will quit the program otherwise it will perform the operation again.

    Hint:

    Use the formulas given below for conversion.
    K = °C + 273.15
    °F = °C × 95 + 32
    K = (°F + 459.67) × 59


    Sample output of programe:
    help me plz to Solve this Question.-1-png
    -------------------------------
    When user enters option C or c then it convert into Fahrenheit and Kelvin

    help me plz to Solve this Question.-2-png
    ----------------
    When user enters option F or f then it convert into Celsius and Kelvin
    help me plz to Solve this Question.-3-png
    --------------------------
    When user enters option K or k then it convert into Celsius and Fahrenheit
    help me plz to Solve this Question.-4-png-----------------------------

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    what have you tried so far?
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  3. #3
    Registered User
    Join Date
    Oct 2013
    Posts
    6
    bro, i have done some work with the help of my frinds... but not sure about coding.....

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    you have the formulas required to do this. if you know C++, this is an easy task. what part are you having trouble with? can you post some code?
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  5. #5
    Registered User
    Join Date
    Oct 2013
    Posts
    6
    bro i'm new for C++ programming.... my field of study is Accounting. but i also doing MIT (Master of Information Technology). how i post the full code here??? when i trying to post some error msg are shown...

  6. #6
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Use code tags

  7. #7
    Registered User
    Join Date
    Oct 2013
    Posts
    6
    can't understand, how we i use Code tag to put my code here....

  8. #8
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by ansabch View Post
    can't understand, how we i use Code tag to put my code here....
    the link that Matticus posted explains in great detail.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  9. #9
    Registered User
    Join Date
    Oct 2013
    Posts
    6
    Code:
    
    
    Code:
    #include <iostream.h>
    main()
    {
    double f_temp, k_temp, c_temp, temp;
    char ch, quit;
    
    
    cout << " *********** Temprature Conversion Calculator **************";
    cout << "\n\n Please enter the temprature unit for which you want the coverison ";
    cout << "\n 1. F for Fahrenheit to Celcius and Kalvin"; 
    cout << "\n 2. C for Celsius to Fahrenheit and Kalvin";
    cout << "\n 3. K for Kalvin to Fahrenheit and Celcius";
    startagain:
    
    
    cout << "\n\n Please enter you choice: ";
    cin >> ch;
         
         switch(ch)
         {           
         case 'f':
         case 'F':              
                cout << " Please enter temprature in Farhenheit: ";
                cin >> f_temp;
                c_temp = (f_temp  -  32)  *  5/9;
                k_temp = (f_temp + 459.67) * 5/9;   
                cout << " Celcius =" << c_temp;
                cout << "\n Kelvin =" << k_temp;
                cout << "\n Do you want to calculate another value (y/n): ";
                cin >> quit;
                if (quit == 'y' || quit == 'Y')
                goto startagain;
                break;
                
         case 'c':
         case 'C':              
                cout << " Please enter temprature in Celcius: ";
                cin >> c_temp;
                k_temp = c_temp + 273.15 ;
                f_temp = c_temp  *  9/5 + 32;   
                cout << " Kelvin =" << k_temp;
                cout << "\n Farhenheit =" << f_temp;
                cout << "\n Do you want to calculate another value (y/n): ";
                cin >> quit;
                if (quit == 'y' || quit == 'Y')
                goto startagain;
                break;
                
         case 'k':
         case 'K':            
                cout << " Please enter temprature in Kelvin: ";
                cin >> k_temp;
                c_temp = k_temp - 273.15 ;
                f_temp = (k_temp - 273.14)  * 9/5 + 32;  
                cout << " Celcius =" << c_temp;
                cout << "\n Farhenheit =" << f_temp;
                cout << "\n Do you want to calcute another value (y/n): ";
                cin >> quit;
                if (quit == 'y' || quit == 'Y')
                goto startagain;
                break;
                
         default: 
                cout << "\n Invalid Choice";             
         }
    cout << endl<<endl;
    system("pause");    
    }

  10. #10
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You may want to check with your instructor about how many points you're going to lose by using a goto instead of a loop construct (such as do-while).

    You may want to change 5/9 to 5.0/9.0, as depending on when your operators get evaluated you might lose the remainder (in C++ 5/9 is 0, while 5.0/9.0 is 0.555556) (and ditto for 9/5). (EDIT: I think this will depend on how aggressive your compiler is on optimizing, though; you should be okay in this particular case by left-to-right grouping. If it were me, though, I'd be typing 5.0/9.0 anyway.)

    Edit to add: And of course you've typed 273.15 differently in your kelvin conversions.
    Last edited by tabstop; 11-20-2013 at 11:15 AM.

  11. #11
    Registered User
    Join Date
    Nov 2013
    Posts
    12
    First things first, shouldn't he correct line 2)
    Code:
     main()
    to
    Code:
     int main()

  12. #12
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Quote Originally Posted by tabstop View Post
    (EDIT: I think this will depend on how aggressive your compiler is on optimizing, though; you should be okay in this particular case by left-to-right grouping. If it were me, though, I'd be typing 5.0/9.0 anyway.)
    Typing 5.0/9.0 or even 5.0/9 is probably a good idea for readability purposes. I'd probably have it as a named constant anyway/

    However compilers don't typically (ever?) change the order of evalutation of floating point expressions, because floating point expressions are not necessaily associative (see quote below) and, therefore, the compiler always errs on the side of caution and assumes the programmer wrote the expression exactly how they wanted it. I know that gcc won't change the order unless you force it to (using -ffast-math) and it would make sense that other compilers behaved similarly. Whether or not this behaviour can be relied upon is another story -- I haven't looked at what the Standard says about IEEE754.

    From Floating point - Wikipedia, the free encyclopedia
    While floating-point addition and multiplication are both commutative (a + b = b + a and a×b = b×a), they are not necessarily associative. That is, (a + b) + c is not necessarily equal to a + (b + c).

  13. #13
    Registered User
    Join Date
    Oct 2013
    Posts
    6
    plz point-out if u saw a error or any mistakes in codes.. plz plz this is my first programme

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 10-20-2013, 10:47 PM
  2. Help me solve this programming question please......
    By kavi.84 in forum C Programming
    Replies: 3
    Last Post: 07-10-2012, 05:09 AM
  3. Help me solve dis question..Please
    By imbax in forum C Programming
    Replies: 2
    Last Post: 09-23-2010, 09:25 PM
  4. how to solve this question?
    By zcrself in forum C Programming
    Replies: 9
    Last Post: 03-10-2010, 12:12 AM
  5. a question that i can't solve
    By revolution3396 in forum C Programming
    Replies: 16
    Last Post: 11-19-2008, 06:36 PM

Tags for this Thread