English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

int main() {
int num1, num2, sum;

cout << "Please enter first number: ";
cin >> num1;
cout << "Please enter second number: ";
cin >> num2;

sum = num1 + num2;
cout << "The sum is " << sum << endl;

return 0;
}

I am supposed to use this sample program to calculate the temperature conversion like

°C = 5/9 (°F - 32)

To find degrees Fahrenheit when you know the Celsius temperature use this equation:

°F = 9/5 °C + 32

To find degrees in Kelvin when you know the Celsius temperature use this equation:

°K = °C + 273.15

To find degrees in Rankine when you know the Fahrenheit temperature use this equation:

°R = °F + 459.67

It looks like the input should be in farenheit and produce 4 outputs of different concersion of temps.

If ayone can help me with this I'd appreciate it very much.

2007-02-14 11:54:03 · 4 answers · asked by Anonymous in Computers & Internet Programming & Design

I am supposed to use this sample
and change the variables and stuff to make the conversion happen. This is what i did so far


int main() {
double fahrenheit, celsius, kelvin, rankine;

// display initial program identification
cout << "Simple C Program - Don Retzlaff "
<< "donr@unt.edu" << endl << endl;

// prompt the user for input
cout << "Please enter temp: ";
cin >> fahrenheit;


celsius = (5/9)*(fahrenheit - 32);
cout << "the temp is " << celsius << endl;
fahrenheit = 9/5 *(celsius + 32);
cout << "the temp is " << fahrenheit << endl;
kelvin = celsius + 273.15;
cout << "the temp is " << kelvin << endl;
rankine = fahrenheit + 459.67;
cout << "the temp is " << rankine << endl;


return 0;
}

This compiles right, but only output I get is the constants. The input is not calculated for some reason.

2007-02-14 12:10:30 · update #1

4 answers

I made few changes to your program... I hope u would get them. If not understood u r self, u can query me again.
However, below is u r modified solution.


#include
int main() {
double fahrenheit, celsius, kelvin, rankine;

// display initial program identification
cout << "Simple C Program - Don Retzlaff "
<< "donr@unt.edu" << endl << endl;

// prompt the user for input
cout << "Please enter temp: ";
cin >> fahrenheit;


celsius = (5.0/9)*(fahrenheit - 32);
cout << "the temp is " << celsius << endl;
fahrenheit = (9.0/5) *(celsius) + 32;
cout << "the temp is " << fahrenheit << endl;
kelvin = celsius + 273.15;
cout << "the temp is " << kelvin << endl;
rankine = fahrenheit + 459.67;
cout << "the temp is " << rankine << endl;


return 0;
}


OM NAMAH SHIVAY

2007-02-16 04:10:25 · answer #1 · answered by Gurudev 3 · 0 0

Are you supposed to ask them what temperature they have and what they want it converted to? If so, then you're missing a few things. I'll add comments below...


int main() {
double fahrenheit, celsius, kelvin, rankine;

// display initial program identification
cout << "Simple C Program - Don Retzlaff "
<< "donr@unt.edu" << endl << endl;

// prompt the user for input
cout << "Please enter temp: ";
cin >> fahrenheit;

celsius = (5/9)*(fahrenheit - 32);
cout << "the temp is " << celsius << endl;
// Note: You should on the above line say that it's celcius.

// You already have farenheit - or so you assume so -
// so don't change it here.
//fahrenheit = 9/5 *(celsius + 32);
cout << "the temp is " << fahrenheit << endl;
// again, say that it's farenheit

kelvin = celsius + 273.15;
cout << "the temp is " << kelvin << endl;
rankine = fahrenheit + 459.67;
cout << "the temp is " << rankine << endl;
// again, on the above two cout lines, say what temp name it is

return 0;
}

Once you make those changes, you can begin to add more to ask the user what kind of temp they are entering and then calculate the others based on that.

2007-02-14 12:27:15 · answer #2 · answered by BigRez 6 · 0 1

ok. I'm going to need clarifications. The code block that adds the 2 numbers, do they have anything to do with temp. conversion?

I see you have the code, would you please explain exactly the numbers you see as output?
Also, your equation of Celcius-Fahrenheit & the code's equation are conflicting. I would check for the placement of parentheses.

If I don't get back to this in next few hours, please feel free to email me
yungr01@yahoo.com

2007-02-14 11:58:20 · answer #3 · answered by yungr01 3 · 0 1

The modulus operator in c++ is %. So, you may remedy the question making use of a= xpercent2 and if a=0 then the integer huge variety entered is Even in the different case it really is unusual. you should use conditional operator ? and : to envision this challenge like this : (apercent2==0)?cout<<"Even huge variety ":cout<<"unusual huge variety." ;

2016-11-03 11:37:56 · answer #4 · answered by Anonymous · 0 0

fedest.com, questions and answers