plz help me to solve this Question
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: plz help me to solve this Question

  1. #1
    Join Date
    Oct 2013
    Posts
    7

    Post plz help me 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 × 9⁄5 + 32
    K = (°F + 459.67) × 5⁄9


    Sample output of program:
    Name:  1.png
Views: 329
Size:  7.8 KB

    ---------------------------------------
    When user enters option C or c then it convert into Fahrenheit and Kelvin
    Name:  2.png
Views: 326
Size:  9.4 KB

    ----------------------------------------
    When user enters option F or f then it convert into Celsius and Kelvin
    Name:  3.png
Views: 331
Size:  11.9 KB

    ------------------------------------------
    When user enters option K or k then it convert into Celsius and Fahrenheit
    Name:  4.png
Views: 332
Size:  15.1 KB

  2. #2
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,272

    Re: plz help me to solve this Question

    plz help me to solve this Question
    First design the program, then code the design the test/debug the code.

    As this is an assignment, no one here is going to write the code for you as that would be considered cheating. See http://forums.codeguru.com/showthrea...ork-assignment

    Once you have produced some code, if you want to post it here we'll provide further guidance and advice.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  3. #3
    Join Date
    Oct 2013
    Posts
    7

    Re: plz help me to solve this Question

    ok i will send u the code of this Question.. check and tell me if u see any error in it... ok bro

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,057

    Re: plz help me to solve this Question

    Quote Originally Posted by ansabch View Post
    ok i will send u the code of this Question.. check and tell me if u see any error in it... ok bro
    That's not the way this forum works. 2kaud isn't your private, personal consultant. Post your code publicly along with any questions you have. Please use code tags when you do.

  5. #5
    Join Date
    Oct 2013
    Posts
    7

    Re: plz help me to solve this Question

    how i use code tags in my code for post here????

  6. #6
    Join Date
    Oct 2013
    Posts
    7

    Re: plz help me to solve this Question

    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");    
    }

  7. #7
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,272

    Re: plz help me to solve this Question

    First make sure your code is properly formatted. In Quick Reply click Go Advanced then paste the code. make sure the code is selected and click '#'.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  8. #8
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,272

    Re: plz help me to solve this Question

    Code:
    #include <iostream.h>
    main()
    This is not standard c++. What compiler/system are you using? This should be
    Code:
    #include <iostream>
    int main()
    Code:
    startagain:
    using labels and goto statements in c++ code, whilst syntactically correct, is not to be recommended as it leads to unreadable and hard to follow/debug code. It would be usual to have a loop (do .. while) controlling the iterations. Also as the same question re calculating another value is asked in all three cases, it would be better to only code the question once at the end of the switch, the answer being used to control the while condition for repeats.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  9. #9
    Join Date
    Oct 2013
    Posts
    7

    Re: plz help me to solve this Question

    plz point-out if u saw a error or any mistakes in codes.. plz plz this is my first programme

  10. #10
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,272

    Re: plz help me to solve this Question

    Have you read my post #8?
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  11. #11
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,057

    Re: plz help me to solve this Question

    Quote Originally Posted by ansabch View Post
    plz point-out if u saw a error or any mistakes in codes.. plz plz this is my first programme
    This is the first time in this thread you've actually said what you want. 2kaud pointed out several problems. I don't see anything else glaringly wrong, other than "kalvin" should be "kelvin".

  12. #12
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,526

    Re: plz help me to solve this Question

    Quote Originally Posted by ansabch View Post
    plz point-out if u saw a error or any mistakes in codes.. plz plz this is my first programme
    Not too bad for the first program!
    In addition to what 2kaud said, you need to add
    Code:
    using namespace std;
    for this code to compile.
    Makes me wonder - how did you write that much code without compiling it at least once???

    Your prompts do not much the provided samples (minor issue?).
    The specification doesn't say what to do in case of invalid choice; I would probably go to the prompt again.
    Try entering K for Kelvin and -1 for the temperature. What is the expected output?
    There is a compiler warning about unused variable; that should be cleaned up.
    Did you already learn about functions? If yes - there should be no repeated code blocks; if no - how come the "goto" was taught first???
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinViewer - an integrated GDI objects viewer for Visual C++ Debugger, and more...

  13. #13
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,272

    Re: plz help me to solve this Question

    how come the "goto" was taught first???
    How come 'goto' was taught at all!
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  14. #14
    Join Date
    Apr 1999
    Posts
    27,423

    Re: plz help me to solve this Question

    Quote Originally Posted by ansabch View Post
    plz point-out if u saw a error or any mistakes in codes.. plz plz this is my first programme
    I'll just give a comment about your use of goto:

    If you post a C++ program using goto, there is a very big chance you won't get any help (except to tell you to get rid of the goto). A tutor or experienced programmer will tend not to waste their time trying to figure out a program that uses goto.

    Without proper looping structures, your code will end up like this:

    http://en.wikipedia.org/wiki/Spaghetti_code

    Do you think that anyone would want to try to figure code out that looks like spaghetti?

    Regards,

    Paul McKenzie

  15. #15
    Join Date
    Oct 2013
    Posts
    7

    Re: plz help me to solve this Question

    plz someone help me to writing comment in code.... i am not able to write comment on avery funcition. plzzzzzzzzzzzzzzzz

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center