I am attempting to learn how to pass variables through a menu using functions. Problem is, at no point was taught how to do so. As you can imagine, any variables I would enter in the first menu function to normally utilize in my cases/other functions such as
if (count==0)
{
low = number;
high = number;
count++;
sum = number;
}
else
{
if (number < low)
number = low;
if (number > high)
high = number;
count ++;
sum += number;
}
Will not pass through function 2, as anyone more knowledgeable with C would realize. It will not work in int main either. How would one go about defining user entered numbers,highest,lowest,etc. To the other functions? Here is what I have so far, the loop and menu works fine.
#include<stdlib.h>
#include<stdio.h>
int menuChoice()
{
int choice;
printf("1.Enter a number\n");
printf("2.Display Highest Number Entered\n");
printf("3.Display Lowest Number entered\n");
printf("4.Display Average of Numbers Entered\n");
printf("5.Quit\n");
printf("Enter your choice: ");
scanf("%i", &choice);
return choice;
}
int function1()
{
int number;
printf("Enter a number:\n");
scanf("%i", &number);
return number;
}
int function2()
{
}
int function3()
{
}
int function4()
{
}
int main()
{
int quit = 0;
while (quit != 1)
{
int menu;
menu = menuChoice();
switch (menu)
{
case 1:
function1();
break;
case 2:
function2();
break;
case 3:
function3();
break;
case 4:
function4();
break;
case 5:
quit = 1;
break;
default:
printf("Please enter 1 through 5\n");
}
}
return 0;
}