My first c program - HELP!!
HELP! This is my first c program so i apologize if the technique is poor. My basic problem is that when the user inputs an invalid integer for the menu which is then processed by the function menuProcessor, the program goes into an infinite loop of printing the menu to the screen and clearing the screen, never again asking for a new menuItem input. Why is this happening?! I simply want menuProcessor to call menu again until a valid menuItem input is entered. Thanks!
Code:
#include <stdio.h>
void menu();
void menuProcessor(int);
int main () {
int numbers[20] = {33, 77, 99, 2, 4, 1, 7, 12, 65, 3, 78, 5, 8, 10, 28, 27, 67};
menu();
//getch();
return 0;
}
void menu () {
int menuItem;
system("cls");
printf("Please select from the following options:\n");
printf("1. Print the content of the array\n");
printf("2. Compute the average of the array\n");
printf("3. Compute the sum of the array\n");
printf("4. Print the content of the array in reverse order\n");
printf("5. Add a value to each element of the array\n");
printf("6. Exit\n");
scanf("%d", &menuItem);
menuProcessor(menuItem);
return;
}
void menuProcessor (int menuItem) {
if ((menuItem < 1) || (menuItem > 6)) menu();
return;
}