jeudi 18 février 2021

Why is my first else not working? And will the rest of my code work fine?

i dont understand why my first else has an error whenever i try to run. I am completely new to c programming.

#include <stdio.h>
#include <math.h>

int main(){
double x, ans, e, ln, r, m;
int i;
char oper;
for (i=1; i<=10; i++){
    
    printf("Enter your number: ");
    scanf("%f", &x);
    
    printf("What operation would you like to do? (e,/,r,m)");
    scanf("%c",&oper);
    
if (oper=='e')
    e = exp(x);
    ans = e;
else
    if (oper=='/')
        ln = log(x);
        ans = ln;
    else
        if (oper=='r')
            r = sqrt(x);
            ans = r;
        else
            if (oper=='m')
                m = abs(x);
                ans = m;
printf("Your answer is: %f", &ans); 
    
    }

    

}

Also I am not sure if the rest of my code is good or not due to the else problem I am having.

Aucun commentaire:

Enregistrer un commentaire