# First assignment help

• 06-28-2004
FirstC++
First assignment help
This is my first C++ class and I stuck on the first assignment.
this is the assignment:

"The formula to convert Fahrenheit to Centigrade is: c = 5/9 * (f – 32)

There is also an approximation of the conversion given by taking half the Fahrenheit temperature and subtracting 15. You want to do it both ways and determine how good of an approximation this is.

Write a C++ program that prompts the user for a temperature in Fahrenheit, computes the centigrade equivalent using the actual formula, computes the approximation, and computes the percent difference between the two.

Your program must check that the Fahrenheit temperature is in the range:
-30 <= F <= 120
If the Fahrenheit temperature is not within this range, print out an appropriate message and terminate the program.

Input: Temperature in Fahrenheit

Output:
1. Temperature in Fahrenheit
2. Actual temperature in centigrade using (c = 5/9 * (f – 32) )
4. percent difference between the approximation and the actual temperature."

Can some please show exactly how I would type in that calculation?

Thanks Leon
• 06-28-2004
skorman00
Writing equations in C++ works pretty much the same way how you would write it out. If you're not sure on what the equations are, you should be looking elsewhere. If you're confused on something such as syntax, what specificly are you having troubles with?
• 06-29-2004
The Brain
:)
That.. was exactly my first assigment in c++ as well :D
• 06-29-2004
quzah
You've got the calculation. Just declare your variables c and f, and fill them accordingly.

Quzah.
• 06-29-2004
DougDbug
Equations, expressions, and assignment-statments
In C++ (and every other programming language I know of) the equal sign is the assignment operator. It assigns the value on the right to the variable on the left. This means that everything on the right must be defined (known). And, the expression on the right must evaluate to a value.

x = 3; //OK
y = x + 3; //OK if x is defined
c = (5.0/9.0 * (f – 32) ); / /OK if f is defined

2 = x; //NO!
x + 2 = 3; // NO!

Note that you might have to put decimals in 5.0/9.0 so that the compiler stores the division-result as a float.
• 06-30-2004
FirstC++
Thanks guys, I got it now

Leon
• 07-01-2004
quzah
Quote:

x + 2 = 3; // NO!
That depends on what x is defined as. This could be legal.

Quzah.
• 07-01-2004
raum
Quote:

Originally Posted by quzah
That depends on what x is defined as. This could be legal.

Quzah.

Legal? As in it will compile or as in it's doing what he wants it to do? It should compile fine, unless x is undeclared then maybe some error will be given. Throw it in a conditional statement and it will work, but neither one of those is what he 'wants' to do.

Wow, not only was this like my 3rd assignment in HS, my first one in college but I've helped like 5 irl people do this. Mainly just make sure that you have 5.0/9.0. That usually is the problem. If your taking a class, I would suggest remembering that well for the test :p