# Thread: help me plz to Solve this Question.

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

-------------------------------
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. what have you tried so far?

3. bro, i have done some work with the help of my frinds... but not sure about coding.....

4. 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?

5. 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. Use code tags

7. can't understand, how we i use Code tag to put my code here....

8. Originally Posted by ansabch
can't understand, how we i use Code tag to put my code here....
the link that Matticus posted explains in great detail.

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

11. First things first, shouldn't he correct line 2)
Code:
` main()`
to
Code:
` int main()`

12. Originally Posted by tabstop
(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. plz point-out if u saw a error or any mistakes in codes.. plz plz this is my first programme