im writing a calculator program in c and having some trouble..
basically it needs to have + - / * ^ functions as well as an integer only mode
the code so far
#include <stdio.h>
#include <ctype.h>
#include <math.h>
int main(int argc, char *argv[]) {
float acc, num;
char op;
float do0p(char op, float num1, float num2) {
select (op) {
case + : return num1 + num2;
break;
case - : return num1 - num2;
break;
case * : return num1 * num2;
break;
case / : return num1 / num2;
break;
case ^ : return pow(num1,num2);
break;
default: return num1;
}
}
printf("Welcome to calculator!\n");
while(1) {
scanf("%f", acc);
while(1) {
do op = getchar(); while(isspace(op));
if(op == 'q') return 0;
else if(op == 'c') break;
scanf("%f", num);
acc = do0p(op, acc, num);
printf("%d", acc);
}
}
return 0;
}
for somereason the program isnt working and i still am not sure how to add an integer only mode
any help would be nice