Reputation: 3
I found that the void main
isn't correct but even when I change it to int
or erase it,
I'm not getting what I'm supposed to which is the value for X given the values for A and B for the equation ax+b=0 and all I get are zeroes.
How can i fix this ?
void main()
{
float a,b,x=0;
printf("\n Write the values for A and B");
scanf("&%F&%F",&a,&b);
if(a==0)printf("\n Not a valid operation");
else{x=-b/a;
printf("\n Answer is x=%f",x);
}
}
Upvotes: 0
Views: 286
Reputation: 206667
Your use of the format specifiers to read a
and b
seem strange. Not sure whether you meant to have those &
in there. Checkout the details of the valid format specifiers at http://en.cppreference.com/w/cpp/io/c/fscanf.
Try:
scanf("%f%f",&a,&b);
&
is not a format specifier. When you use
scanf("&%F&%F",&a,&b);
scanf
expects the characters &
in the input stream.
Upvotes: 1