Run-Time Check Failure #3 - The variable 'x' is being used without being initialized

i am new to C language , i was writing a small program but faced a problem "Run-Time Check Failure #3 - The variable 'x' is being used without being initialized"

please help , here's my program :
#include <stdio.h>
int main(void)
{
int x,y,a=x+y,b=x-y,c=x*y,d=x/y,e;
printf("Enter First Number\t");
scanf("%d",&x);
printf("Enter Second Number\t");
scanf("%d",&y);
printf("Choose Fuction\n a: Addition\n b: Subtraction\n c: Multiplication\n d: Division\n ");
scanf("%d",&e);
printf("%d",e);
while(1);
return 0;

}
what did i do wrong ?
1
2
3
4
5
6
7
int x =0;
int y = 0;
int a= x+y;
int b= x-y;
int c = x * y;
int d = x / y; // you will get divide by zero exception here, so you will need to change the code
int e = 0;
this didnt work :/
This error is exactly what it says:

 
int x,y,a=x+y,b=x-y,c=x*y,d=x/y,e;


Here, when you do a=x+y, you have not set x (or y) to anything. So the computer does not know what numbers you want to add.

Remember that programs are executed in order, so you must get x and y from the user before you attempt to add them together or do other operations with them.
oh ok thank you , now i understand the problem
it worked
Topic archived. No new replies allowed.