# Thread: Help with almost solved problem

1. ## Help with almost solved problem

I am a newbie when it come to C++ but I think I am close to solving this code. Can anyone tell me where my mistake is. I am having on the Temperature reading.

Code:
```#include<stdio.h>

iint choice; /* 1 to convert celsius, 2 to convert fahrenheit. //
int c; // degrees in celsius//
int f; // degrees in fahrenheit//
float ctemp, ftemp; //temperatures//

int main ( void )

{
printf( "This program converts from celsius to fahrenheit and fahrenheit to celsius.\n" );

printf( "Enter 1 for Fahrenheit to Celsius or 2 for Celsius to Farenheit.\n" );

scanf("%d", &choice); //input from user//

if (choice == 1)
{
printf( "Enter degrees in Fahrenheit.");
scanf ("%d", &f);
ctemp = (5/9) * (f-32);
printf ( "Temperature in Celsius is", ctemp); //Degrees in celsius//
}
else{
if (choice == 2)
{
printf( "Enter degrees in Celsius.");
scanf ("%d", &c); //get degrees celsius from user//
ftemp = (9/5) * (c+32);
printf ( "Temperature in farenheit is", ftemp); //output degrees in celsius//
}
else
}

return 0; //end program//
}```

2. 5/9 is zero, and multiplying anything by zero gives zero. Similarly 9/5 is one, and one times anything is itself. (Perhaps you want 5.0/9.0 etc.)

3. I tried it but, I still get same results. Thanks for the pointer, I added it to code.

4. Originally Posted by Kaname
I am a newbie when it come to C++ but I think I am close to solving this code. Can anyone tell me where my mistake is. I am having on the Temperature reading.

Code:
```#include<stdio.h>

iint choice; /* 1 to convert celsius, 2 to convert fahrenheit. //
int c; // degrees in celsius//
int f; // degrees in fahrenheit//
float ctemp, ftemp; //temperatures//

int main ( void )

{
printf( "This program converts from celsius to fahrenheit and fahrenheit to celsius.\n" );

printf( "Enter 1 for Fahrenheit to Celsius or 2 for Celsius to Farenheit.\n" );

scanf("%d", &choice); //input from user//

if (choice == 1)
{
printf( "Enter degrees in Fahrenheit.");
scanf ("%d", &f);
ctemp = (5/9) * (f-32);
printf ( "Temperature in Celsius is", ctemp); //Degrees in celsius//
}
else{
if (choice == 2)
{
printf( "Enter degrees in Celsius.");
scanf ("%d", &c); //get degrees celsius from user//
ftemp = (9/5) * (c+32);
printf ( "Temperature in farenheit is", ftemp); //output degrees in celsius//
}
else
}

return 0; //end program//
}```
There are a whole lot of things to be pointed out in your code-
1. This is not a C++ code, it's perfectly C, so you posted in a wrong section.
2. There is nothing called "iint" in C.
3. Comment your code properly. If you've started with /* so you should end up with */ not //. // is a single line comment used with one lines only. For eg. here is a single line comment:
int i; //this is a comment
4. As tabstop mentioned change 5/9 and 9/5 to 5.0/9 and 9.0/5.
5. Use proper format specifier to print the required value. eg %f in you case.
6. It would be better not to make global declarations for all the variables.

5. I figured it out thanks for all the help.
Code:
```#include<stdio.h>
int choice; // 1 for Celsius, 2 for Fahrenheit. //
int a; // Temperature value//
int ctemp; // Celsius //
int ftemp; // Fahrenheit //

int main( void )

{
printf( "This program converts from Celsius to Fahrenheit or Fahrenheit to Celsius.\n" );
printf( "Enter 1 for Fahrenheit to Celsius or 2 for Celsius to Farenheit.\n" );
scanf("%d", &choice); // User input //

if (choice == 1)
{
printf( "Enter degrees in Fahrenheit.");
scanf ("%d", &a); // User input //
ctemp = (5.0/9.0) * (a-32); //  function //
printf ( "%d", ctemp); // Degrees in celsius //
}
else if (choice == 2)
{
printf( "Enter degrees in Celsius.");
scanf ("%d", &a); // User Input //
ftemp = (9.0/5.0) * a +32; // function //
printf( "%d", ftemp); // Degrees in Fahrenheit //
}
else
printf( "Only can choose 1 or 2" );

return 0; //end program//
}```

6. Still your commenting is wrong.