can ny1 pls tell me ,why the following code is wrong?
#include<stdio.h>
int main()
{
int x;
float y;
scanf("%d%.2f",&x,&y);
if((x%5==0) && (x +.50) <= y)
{y=y-(x+.50);}
printf("%.2f",y);
return 0;
}
can ny1 pls tell me ,why the following code is wrong?
#include<stdio.h>
int main()
{
int x;
float y;
scanf("%d%.2f",&x,&y);
if((x%5==0) && (x +.50) <= y)
{y=y-(x+.50);}
printf("%.2f",y);
return 0;
}
There is an error in taking input.
First refer the execution of the code at IDEONE.com
.This code just take a float input and simply displays it.
Isn’t the above code in IDEONE.com gives you an idea that scanf("d.2f",&x,&y) is not the correct way/format of taking float input.
This is the precise way ::
scanf("%d%f",&x,&y);
A format specifier follows this prototype:%[li][width][modifiers]type.Refer this page .
[/li]
So this is the correct code,it will Get Accepted Now.I have removed the bug that i just pointed out.
enter code here
#include<stdio.h>
int main()
{
int x;
float y;
scanf("%d%f",&x,&y);/*HERE scanf("%d%.2f",&x,&y); WAS THE ERROR*/
if((x%5==0) && (x +.50) <= y)
{
y=y-(x+.50);
}
printf("%.2f\n",y);
return 0;
}