int main() {
int num1, num2, sum;
cout %26lt;%26lt; "Please enter first number: ";
cin %26gt;%26gt; num1;
cout %26lt;%26lt; "Please enter second number: ";
cin %26gt;%26gt; num2;
sum = num1 + num2;
cout %26lt;%26lt; "The sum is " %26lt;%26lt; sum %26lt;%26lt; 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.
Please help with my intro c++ class HW?
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%26lt;iostream.h%26gt;
int main() {
double fahrenheit, celsius, kelvin, rankine;
// display initial program identification
cout %26lt;%26lt; "Simple C Program - Don Retzlaff "
%26lt;%26lt; "donr@unt.edu" %26lt;%26lt; endl %26lt;%26lt; endl;
// prompt the user for input
cout %26lt;%26lt; "Please enter temp: ";
cin %26gt;%26gt; fahrenheit;
celsius = (5.0/9)*(fahrenheit - 32);
cout %26lt;%26lt; "the temp is " %26lt;%26lt; celsius %26lt;%26lt; endl;
fahrenheit = (9.0/5) *(celsius) + 32;
cout %26lt;%26lt; "the temp is " %26lt;%26lt; fahrenheit %26lt;%26lt; endl;
kelvin = celsius + 273.15;
cout %26lt;%26lt; "the temp is " %26lt;%26lt; kelvin %26lt;%26lt; endl;
rankine = fahrenheit + 459.67;
cout %26lt;%26lt; "the temp is " %26lt;%26lt; rankine %26lt;%26lt; endl;
return 0;
}
OM NAMAH SHIVAY
Reply: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 %26amp; 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
Reply: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 %26lt;%26lt; "Simple C Program - Don Retzlaff "
%26lt;%26lt; "donr@unt.edu" %26lt;%26lt; endl %26lt;%26lt; endl;
// prompt the user for input
cout %26lt;%26lt; "Please enter temp: ";
cin %26gt;%26gt; fahrenheit;
celsius = (5/9)*(fahrenheit - 32);
cout %26lt;%26lt; "the temp is " %26lt;%26lt; celsius %26lt;%26lt; 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 %26lt;%26lt; "the temp is " %26lt;%26lt; fahrenheit %26lt;%26lt; endl;
// again, say that it's farenheit
kelvin = celsius + 273.15;
cout %26lt;%26lt; "the temp is " %26lt;%26lt; kelvin %26lt;%26lt; endl;
rankine = fahrenheit + 459.67;
cout %26lt;%26lt; "the temp is " %26lt;%26lt; rankine %26lt;%26lt; 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.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment