# I'm new to progamming. I'm not a student. not hom Just tring to see what i did wrong!

This is a discussion on I'm new to progamming. I'm not a student. not hom Just tring to see what i did wrong! within the C++ Programming forums, part of the General Programming Boards category; This is my code and i dont know what i did wrong. When I run it; It ask for a ...

1. ## I'm new to progamming. I'm not a student. not hom Just tring to see what i did wrong!

This is my code and i dont know what i did wrong.
When I run it; It ask for a number the it says the result is celcius.
If any one can please do. Feel free to try the code your self

[html]
[body]
[tag]
Code:
```//
// Conversion - Program to convert temperature from
//              Fahrenheit degreees into Celcius:
//              Fahrenheit = Celcius  9/5 + 32 =
//
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;int main (int nNumberofargs, char* pszArgs [] )
{
// enter the tempature in Fahrenheit
int Fahrenheit;
cout << "Enter the tepature in Fahrenheit:";
cin >> Fahrenheit;
// Use conversion factor for Fahrenheit
// to Celcius
int factor;
factor = 5 + 32 ;
// use conversion factor to convert Fahrenheit
// into Celcius values
int fahrenheit;
fahrenheit = factor * Fahrenheit/5+32;
// output the results (followed "by a Newline)
cout << "Celcius value is:" ;
cout >> celcius << endl;
// wait until user is read before terminating program
// to allow the user see the program results
system("PAUSE");
return 0;
}
[/tag]```
[/body]
[/html]

2. No that's okay, we don't need to try your code. If I couldn't understand exactly what it did by just looking at it then I would not consider myself qualified to help you with it.

What you are meant to do is explain what the problem is and post the exact compile errors.

I can see at a glance that you haven't declared a variable called celcius. Instead you have declared two variables called fahrenheit, one with a capital F. You do not need two of them.
You also have your calculation wrong. You seem to want to convert from F -> C but the formula in your comments is for converting back the other way. You need to apply algebra to rearrange the formula to Celcius = (Fahrenheit - 32) * 5 / 9. You do not need any variable called factor at all.

3. You will also not get very good results using integer math when doing the conversions. When all your values are integer values any fractional value is truncated. Example 1/2 will evaluate to zero, not .5. There are no fractions when using integer math. You should probably change your variables to a floating point type and insure all the constants are floating point by using a decimal point, example 1.0/2.0 would yield a floating point value (.5). I would suggest you use the type double.

Jim

4. > cout >> celcius << endl;
Consistency in >> or << would help.

5. This code is an approximation of an example in the C++ for dummies book, I suggest you properly follow the code in there, the explanation and guide to exercise in the book, though it is possible you found it elsewhere i suppose.