I am making a program that inputs three numbers and then calculates a few different things (each thing has to be its own function). The program starts off telling the user their options and waiting for their input. After any of the cases execute the program will print the menu again except it will use the default case, then it will print the menu and ask for a input. Any help would be greatly appreciated.
#include <stdio.h>
#include <stdlib.h>
void greeting() {
printf("Welcome to Dr. Computer's Mathatorium \n"); // this is a seperate function just because
printf("Remember to use capital letters when selecting \n");
}
//This getNum function is used to the get the number
int getNum ()
{
int a;
printf("Enter your first integer:"); //tells user to input number
scanf("%i", &a); //input
return a;
}
// gets the sum of the numbers
int getSum (int f, int g, int h)
{
return (f + g + h);
}
// gets the sum of the numbers
int getPro (int f, int g, int h)
{
return (f * g * h);
}
// gets the sum of the numbers
int getAvg (int f, int g, int h)
{
return (f * g * h)/3;
}
// gets the sum of the numbers
int getLow (int f, int g, int h)
{
return (f + g + h); //NEEDS ADJUSTING
}
main()
{
int first, second, third, sum, pro, avg, low;
char choice;
greeting ();
do {
printf("Main Menu\n");
printf("A) Get Three Integers\n");
printf("B) Display the Sum\n");
printf("C) Display the Product\n");
printf("D) Display the Average\n");
printf("E) Display the lowest\n");
printf("F) Quit\n");
scanf("%c", &choice);
//here comes the switches to route the choices
switch(choice){
case 'A':
first = getNum ();
second = getNum ();
third = getNum ();
printf("first is: %i\n", first);
printf("second is: %i\n", second);
printf("third is: %i\n", third);
break;
case 'B':
sum = getSum (first, second, third);
printf("sum is: %i\n", sum);
break;
case 'C':
pro = getPro (first, second, third);
printf("product is: %i\n", pro);
break;
case 'D':
avg = getAvg (first, second, third);
printf("average is: %i\n", avg);
break;
case 'E':
avg = getAvg (first, second, third); //NOT DONE YET
printf("average is: %i\n", avg); //REMEMBER TO FIX
break;
default:
printf("INVALID CHOICE!\n");
break;
}
} while (choice != 'F');
return 0;
}