I am getting the following error while executing code on Visual Studio 2019 MSB6006"CL.exe" exited with code 2
#include<stdio.h>
#include<conio.h>
int main()
{
int a, b, c,x;
x = a / (b - c);
printf("\n Enter values of a,b and c");
scanf_s("%d%d%d", &a, &b, &c);
printf("\n The value of x is %d", x);
return 0;
}
Your order of statements is off.
First assign values to
a
,b
, andc
.Only after use those values in calculations.
Note: the return value of
scanf()
should be checked to be sure all ofa
,b
, andc
have valid values.Note 2: I changed your code a little bit: removed non-standard
<conio.h>
, changed the placing of most'\n'
to be more line-oriented, replaced the optionalscanf_s
(this function may not exist in all C11/C18 implementations).