#include #include void calculator(); int main() { int ch, choose = 0, sumCh;/* choose = the choice of the user, sumCh = how many charcters did the user typrd*/ while (choose!=2)/*stop the loop whaen the user types 2*/ { printf("select from the following:\n 1.calculate an equation\n 2. stop\n"); for(sumCh = 0;(ch = getchar())!='\n';) { if (ch!=' ')/*counts the characters*/ sumCh++; if (ch == '1')/*the user wants to calculate an equation*/ choose = 1; else if (ch == '2')/*the user wants to get out from the loop*/ choose = 2; else/*the user entered an ilegal input*/ choose = 10; } if (sumCh == 1)/*checks if the user typed only 1 character(legal)*/ { if (choose == 1)/*calculate the equation if the user typed 1*/ { calculator(); choose = 0; } else/*prints error if the user entered an illegal number*/ { if (choose!=2) printf("\nError, illegal input, try again\n"); } } else/*if the user typed more than one character*/ { printf("\nError, illegal input, try again\n"); choose = 0; } } return 0; }