Reputation: 1
after running the program it asks for age but do not take the input
int main()
{
float age1, age2, age3, avg;
age1 = age2 = 24.0;
printf("How old are you?\n");
scanf("%f\n",&age3);
avg = (age1+age2+age3)/3;
printf("the average age is %f\n",avg);
return 0;
}
Upvotes: 0
Views: 54
Reputation: 3162
The \n
in scanf("%f\n",&age3);
is causing the problem. remove the \n
. refer Using "\n" in scanf() in C
Upvotes: 0
Reputation: 181469
Remove the \n
from the end of your scanf()
format. Any run of one or more whitespace characters (e.g. spaces, tabs, newlines, ...) in the format matches a run of any number of the same. Thus, your scanf()
keeps matching whitespace -- as many newlines as you choose to enter, for example -- until it sees the next non-whitespace character.
Upvotes: 2