mercredi 18 août 2021

C: Exit in if-Statement

i wrote the following code:

int main(void){
    double (*func[]) (double) = {func1, func2, func3};
    int option = 0;
    double sum;
    double result;
    do{
        scanf("%d", &option);
        if(option == 3){
            break;
        }
        scanf("%lf", &sum);
        printf("%.2lf\n", result = (*func[option])(sum));
    } while (option<10);
    return 0;

But when I enter 3 in sum, it will expect another value and exits then. How can i break after entering 3? Also is there a better expression for the do-while-loop instead of option<10. It is supposed to run until option = 3.

Thanks

Aucun commentaire:

Enregistrer un commentaire