-
November 19th, 2013, 06:42 AM
#1
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:
---------------------------------------
When user enters option C or c then it convert into Fahrenheit and Kelvin
----------------------------------------
When user enters option F or f then it convert into Celsius and Kelvin
------------------------------------------
When user enters option K or k then it convert into Celsius and Fahrenheit
-
November 19th, 2013, 06:57 AM
#2
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. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
November 20th, 2013, 07:41 AM
#3
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
-
November 20th, 2013, 08:03 AM
#4
Re: plz help me to solve this Question
Originally Posted by ansabch
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.
-
November 20th, 2013, 11:18 AM
#5
Re: plz help me to solve this Question
how i use code tags in my code for post here????
-
November 20th, 2013, 11:24 AM
#6
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");
}
-
November 20th, 2013, 11:28 AM
#7
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. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
November 20th, 2013, 11:37 AM
#8
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()
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. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
November 21st, 2013, 08:04 AM
#9
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
-
November 21st, 2013, 08:17 AM
#10
Re: plz help me to solve this Question
Have you read my post #8?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
November 21st, 2013, 08:39 AM
#11
Re: plz help me to solve this Question
Originally Posted by ansabch
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".
-
November 21st, 2013, 04:39 PM
#12
Re: plz help me to solve this Question
Originally Posted by ansabch
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:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
November 21st, 2013, 05:01 PM
#13
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. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
November 21st, 2013, 05:36 PM
#14
Re: plz help me to solve this Question
Originally Posted by ansabch
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
-
November 25th, 2013, 09:19 AM
#15
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|