All I'm trying to do is write a very simple loop program in C to enter the ages of four sprogs between 5 and 7. To display their total and average age using do, while and if statements. I also need to display an error message if an invalid number is entered then when there are no more ages to enter to type in -99 to stop the loop and display the results.
Simple... you'd think! :rolleyes:
I appreciate this is really basic stuff but for some unknown reason my compiler dislikes my 'if' statement no matter where I put it in the program and also insists on throwing a hissy fit regarding the last '}'.
Any suggestions would be greatly appreciated.
{
int age1, age2, age3, age4;
float number = -99;
float total;
float average;
do
{
printf ( "Please enter the first child's age\n" );
scanf ( "%f", &age1 );
fflush(0);
printf ( "Please enter the second child's age\n" );
scanf ( "%d", &age2 );
fflush(0);
printf ( "Please enter the third child's age\n" );
scanf ( "%d", &age3 );
fflush(0);
printf ( "Please enter the fourth child's age and press -99 when done\n" );
scanf ( "%d", &age4 );
fflush(0);
total = age1 + age2 + age3 + age4 + number;
average = total / 4;
}
if (( age < 5 ) || ( age > 7 ))
{
printf ( "Error - Age is out of Range\n" );
}
while ( number != -99 );
{
printf ( "The total is %1.2f\n", total );
( "The average is %1.2f\n", average );
}
}
Thanks for looking :cheesy: