hi im still finishing a calculator program. the problem is i am wondering what command to use to break out of multiple loops. my code is
#include <stdio.h>
#include <ctype.h>
#include <math.h>
double do0p(char op, float acc, float num) {
switch (op) {
case '+' : return acc+num;
break;
case '-' : return acc-num;
break;
case '*' : return acc*num;
break;
case '/' : return acc/num;
break;
case '^' : return pow(acc,num);
break;
default: return acc;
}
}
int main(int argc, char *argv[]) {
printf("ECE Assignment 3\n");
printf("Richard Fang\n");
float acc, num;
char op;
printf("Welcome to calculator!\n");
while(1) {
printf("enter first number: ");
scanf("%f", &acc);
printf("\n");
printf("number entered:");
printf("%f\n", acc);
printf("\n");
printf("enter operand:");
while(1) {
do op = getchar(); while(isspace(op));
if(op == 'q') return 0;
else
if(op == 'c') {printf("Calculator Cleared\n");
break;}
else if(op == 'i') {
printf("entering integer mode\n");
//inside integer mode
printf("enter first number: ");
scanf("%f", &acc);
printf("\n");
printf("number entered:");
printf("%f\n", acc);
printf("\n");
printf("enter operand:");
while(1) {
do op = getchar(); while(isspace(op));
if(op == 'q') return 0;
else
if(op == 'c') {printf("Calculator Cleared\n");
break;}
else
if (op == 'f') {printf("Entering Floating mode");
// start of integer mode 2nd half
printf("enter second number:");
scanf("%f", &num);
acc = do0p(op, acc, num);
printf("%f\n", acc);
printf("press q to quit or c to start over: ");
}}
//end integer mode
printf("enter second number:");
scanf("%f", &num);
acc = do0p(op, acc, num);
printf("%f\n", acc);
printf("press q to quit or c to start over: ");
}
}
return 0;
}
im trying to break out of the inner most look which is in red
any advice?
also i was wondering how to make it so that the program only takes integers and disregards any decimal values