123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
#include <stdio.h> #include <windows.h> unsigned temp, status, options; void add_sub(); void mult_dev(); void increm_decrem(); void average(); void menu() { printf("\n\t\t\t * Calculator *\n\n"); printf("\n\tChoose an option" "\n\n\n 1. Addition and subtraction operations" "\n 2. Multiply and divide operations" "\n 3. Increment and Decrement operations" "\n 4. Average of n numbers using arrays" "\n 5. Exit program" "\n\n Select: "); status = scanf("%d", &options); while(status != 1) { while((temp = getchar()) != EOF && temp != '\n') { printf("\n\n Invalid option.."); Sleep(1500); printf("\n\n Choose 1, 2, 3, 4 or 5\n"); Sleep(1500); system("cls"); printf("\n\t\t\t * Calculator *\n\n"); printf("\n\tChoose an option" "\n\n\n 1. Addition and subtraction operations" "\n 2. Multiply and divide operations" "\n 3. Increment and Decrement operations" "\n 4. Average of n numbers using arrays" "\n 5. Exit program" "\n\n Select: "); status = scanf("%d", &options); } } } int main() { menu(); int i; for(i = 0; i < options;) { if(options == 1) { printf("\n\n\t 1. Addition and subtraction operations"); add_sub(); } else if(options == 2) { printf("\n\n\t 2. Multiply and divide operations"); mult_dev(); } else if(options == 3) { printf("\n\n\t 3. Increment and Decrement operations"); increm_decrem(); } else if(options == 4) { printf("\n\n\t 4. Average of n numbers using arrays"); average(); } else if(options == 5) { printf("\n\n\t 5. Exit program"); printf("\n\n\t\tPress any key to close the console !"); Sleep(1500); system("cls"); break; } else { printf("\n\n Invalid option.."); Sleep(1500); printf("\n\n Choose 1, 2, 3, 4 or 5\n"); Sleep(1500); system("cls"); menu(); } } return 0; } . . . .
while((temp = getchar()) != EOF && temp != '\n')