# help with errors

• 10-08-2007
help with errors
the question is :

enter an odd number (integer)
enter an even number (integer)
enter the same odd number (real)
enter the same even number (real)

so what i did so far..

Code:

```#include <stdio.h> int main() {   int number1;   int number2;   int sum;   int product;   int difference;   int quotient;   float number3;   float number4;   float sum;   float product;   float difference;   float quotient;   printf( "Enter an odd number\n" );   scanf( "%d", &number1 );   printf( "Enter an even number\n" );   scanf( "%d", &number2 );   printf( "Enter the same odd number\n" );   scanf( "%f", &number3 );   printf( "Enter the same even number\n" );   scanf( "%f", &number4 );   sum = number1 + number2;   printf( "Sum of the integers is %d\n", sum );   product = number1 * number2;   printf( "Product of the integers is %d\n", product );   difference = number1 - number2;   printf( "Difference of the integers is %d\n", difference );   quotient = number1 / number2;   printf( "Quotient of the integers is %d\n", quotient );   sum = number3 + number4;   printf( "Sum of the real numbers is %f\n", sum );   product = number3 * number4;   printf( "Product of the real numbers is %f\n", product );   difference = number3 - number4;   printf( "Difference of the real numbers is %f\n", difference );   quotient = number3 / number4;   printf( "Quotient of the real numbers is %f\n", quotient );   return 0; }```
the error is because of the declaration of sum, product, difference, quotient

but if i get rid of int sum etc etc, or float sum etc etc that wouldnt give me the answer that i wanted, right? (one of the result for either integer or real would be zero)

or did i do wrong right from the beginning? xD

thanks
• 10-08-2007
matsp
You can not have the same name for two variables of different types - how will the compiler be able to tell if you mean the float or integer version of the variable - it is perfectly valid to add two integers and turn it into a float, or the other way around.

So you need to use two variables with different names for the float and integer sum variables.

Or you could have two differnet functions that produce the output, and use sum as a local variable in each function - but I don't think you're quite ready for that stage yet.

--
Mats
• 10-08-2007
ah ok

no wonder it didnt turn out well

i didnt change everything properly earlier when i renamed

float sum to float sum1

and forgotten to change :

sum1 = number3 + numer4;

XD

thanks for the explanation :D