I am writing a program that reads in a number that the user enters, checks to see if it is between 0 and 100, if it is then the number is square rooted. If the number is less than 0, an error message is printed. If the number is between 100 and 200 then the natural log of the number is found and if it is over 200 then the loop terminates.
#include <stdio.h>
#include <math.h>
int main (void)
{
float num;
double x, y;
do {
printf("Please enter a number \n");
scanf("%f", &num);
if (num > 0 && num <= 100)
{
x = sqrt(num);
printf("The square root of the number entered is %f \n", x);
}
else if (num <= 0)
{
printf("Please enter a positive number \n");
}
else (num > 100)
{
y = log(num);
printf("The natural log of the number entered is %f \n", y);
}
} while (num <= 200);
return 0;
}
The problem I am having, is when I build the solution, I get an error statement saying that a ; is expected after the
else (num > 100)
What is the reason for this as I would not expect there to be one needed here?
Aucun commentaire:
Enregistrer un commentaire