plz help me to solve this Question
 CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

# Thread: plz help me to solve this Question

1. Junior Member
Join Date
Oct 2013
Posts
7

## 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

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.

3. Junior Member
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. Elite Member Power Poster
Join Date
Nov 2003
Location
Florida
Posts
12,518

## 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.

5. Junior Member
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. Junior Member
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. ## 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 '#'.

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()```
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.

9. Junior Member
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. ## Re: plz help me to solve this Question

Have you read my post #8?

11. Elite Member Power Poster
Join Date
Nov 2003
Location
Florida
Posts
12,518

## 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".

12. Elite Member Power Poster
Join Date
Aug 2000
Location
New York, NY, USA
Posts
5,656

## 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!
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???

13. ## Re: plz help me to solve this Question

how come the "goto" was taught first???
How come 'goto' was taught at all!

14. Elite Member Power Poster
Join Date
Apr 1999
Posts
27,449

## 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

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. Junior Member
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

#### Posting Permissions

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