Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
815 B
1
Indexable
Never
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
    float num1, num2, geo_mean;
    char waste;
    int flag1, flag2, condition = 1;

    printf("<Enter a non-numerical input to exit the program>\n");
    while(condition){
        printf("Please input your first number: ");
        scanf("%f", &num1);
        if(isdigit(num1) == 0){
            break;
        }
        printf("Please input your second number: ");
        scanf("%f", &num2);
        if(isdigit(num2) == 0){
            break;
        }
        if(num1*num2 >= 0){
            geo_mean = sqrt(num1*num2);
            printf("The geometric mean is %.2f\n", geo_mean);
        }
        else{
            printf("Your input is invalid. Please try again.\n");
        }
    }
    return 0;
}