Hey guys, I'm trying to work on this switch menu and I'm not sure how to call a function with parameters from a case statement. Here is the code for my program so far (not finished with the actual program... Just need help with calling functions from the menu, so please don't comment on anything else as I'm aware that there are other things that still need to be fixed!)
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int menu();
void heading(void);
double getgrades(double s[], int x);
double getdouble(double min, double max, char item[]);
void showgrades(double s[], int count);
double changegrade();
double findgrades();
void message(char msg[]);
int menuerror(int min, int max, char prompt[]);
int prompt(char msg[]);
int quit(void);
/* ================================================================== */
// ** Functions **
int main()
{
int TRUE = 1;
int FALSE = 0;
int select, end = TRUE;
double s;
int x;
int count;
double grade;
double scores[101];
do
{
select = menu();
switch (select)
{
case 1: getgrades((double) s, (int) x); break;
case 2: showgrades((double) s, (int) count); break;
case 3: changegrade(); break;
case 4: findgrades(); break;
case 5: end = quit(); break;
default: message("\n\nPlease make a selection between 1 and 5.\a");
}
}
while (end);
return 0;
}
/* ================================================================ */
int menu()
{
int choice;
system("cls");
printf("Grade Score Database\n\n");
printf("1 = Get Grades\n");
printf("2 = Show Grades\n");
printf("3 = Change Grade\n");
printf("4 = Find Grade\n");
printf("5 = Quit\n\n");
choice = menuerror(1, 5, "Enter your selection");
return(choice);
}
/* ================================================================ */
void heading()
{
system("cls");
printf("Grade Score Database\n\n\n");
return;
}
/* ================================================================ */
double getgrades(double *s, int x)
{
double scores[101];
int z;
for (z = 1; z < 101; z++)
{
printf("Enter a grade, or 0 to quit: ");
scanf("%d", &*(scores+z));
}
while (*(scores+z) != 0);
return 0;
}
/* ================================================================ */
void showgrades(double *s, int x)
{
int z;
double scores[101];
system("cls");
printf("Score Report\n\n");
printf("_Position________Grade_\n\n");
for (z = 1; z < 101; z++)
{
printf(" %2d%20.2lf\n", z, *(s+z));
}
printf("Press ENTER to return to the Main Menu...");
getchar();
}
/* ================================================================ */
void changegrade(double *s, int x)
{
int z;
double total = 0;
system("cls");
printf(" Product Cost by Type\n\n");
printf("_Type_____________Cost_\n\n");
for (z = 1; z < x; z++)
{
printf(" %2d%2d\n", z, *(s+z));
}
printf("Press ENTER to return to the Main Menu...");
getchar();
}
/* ================================================================ */
void message(char msg[])
{
printf("%s\n\n", msg);
}
/* ================================================================ */
int menuerror(int min, int max, char item[])
{
int z;
printf("%s from %d to %d: ", item, min, max);
scanf("%d%*c", &z);
while (z < min || z > max)
{
message("\nError in range. Press Enter to continue.\a");
printf("%s from %d to %d: ", item, min, max);
scanf("%d%*c", &z);
}
return(z);
}
/* ================================================================ */
int prompt(char msg[])
{
int z;
do
{
printf("%s (Y/N)? ", msg);
z = toupper(getchar());
if (z != 'Y' && z != 'N') printf("\nError, please enter Y or N only.\n");
}
while (z != 'Y' && z != 'N');
return(z);
}
/* ================================================================ */
int quit()
{
int TRUE = 1;
int FALSE = 0;
int z, end = TRUE;
z = prompt("\nEnd program\a");
if (z == 'Y')
{
system("cls");
message("\nGrade Score Database Closed Succesfully.");
end = FALSE;
}
return(end);
}
/* ================================================================ */