Menu-driven program in C

This is a menu driven program that allows a user to enter five numbers and then choose between finding the smallest,largest,sum or average.The menu and all the choices are to be functions.Use a switch statement to determine what action to take.Provide an error message if an invalid choice is entered.

I was able to get the sum part to compile and run but the other parts still have errors thats why i commented them.







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <stdio.h>
#include <stdlib.h>


//Function Declarations
int getOption (void);
void getData (int* num1, int* num2, int* num3, int* num4, int* num5);
float calc   (int option, int num1, int num2, int num3, int num4, int num5);
int sum    (int num1, int num2, int num3, int num4, int num5);
float sub    (int num1, int num2, int num3, int num4, int num5);  
int LargestNumber, SmallestNumber, Temp;

int main()
{
//Local Declarations
int option;
int num1;
int num2;
int num3;
int num4;
int num5;
float result, average;
//Statements
  option = getOption ();
  getData (&num1,&num2,&num3,&num4,&num5);
  result = calc (option, num1,num2,num3,num4,num5);
printf("**In main result is: %6.2f\n", result);
   
   return 0;
   getch();
system("PAUSE");	
  }
/*  ==================getOption====================*/
int getOption()
{
//Local Declarations
  int option;
  
//Statements
  printf ("\t***************************************");
  printf("\n\t*                  MENU               *");
  printf("\n\t*                                     *");
  printf("\n\t* 1. LargestNumber                    *");
  printf("\n\t* 2. SmallestNumber                   *");
  printf("\n\t* 3. Sum                              *");
  printf("\n\t* 4. Average                          *");
  printf("\n\t*                                     *");
  printf("\n\t************************************* *");
  
  printf("\n\nPlease type your choice ");
  printf("and key return: ");
  scanf ("%d", &option);
  return option;
} //getOption  
/*======================getData ========================
  This function reads five integers from the keyboard
*/
void getData (int* a, int* b, int* c, int* d, int* e)
{
     printf("Please enter five integer numbers: ");
     scanf ("%d %d %d %d %d", a, b, c, d, e);
     return;
} // getData

/* =======================calc==================================
   This function determines the type of operation and calls a function to perform it.
*/
float calc (int option, int num1, int num2, int num3, int num4, int num5)
{
//Local Declarations
float result;
Temp = num1;

    Temp = num2;
// Statements
   switch(option)
       {
        case 1: //result = largest(num1, num2, num3, num4, num5);
                break;
        case 2: //result = smallest(num1, num2, num3, num4, num5);
                break;
        case 3: result = sum(num1, num2, num3, num4, num5);
                break;
        case 4: if (3.0 == 0.0)
                   {
                     printf("\n\a\aError: ");
                     printf("sum is zero***\n");
                     exit (100);
                   } // if
                  else
                      result = 4.0;
                  break;
                  
                  default: printf("\aOption not available\n");
                           exit  (101);
        } // switch
        printf("**In calc result is: %6.2f\n", result);
        getch();
            return result;
} //calc 
/* =========================== Largest ===============================
This function compares five numbers and returns the largest
*/
int sum (int num1, int num2, int num3, int num4, int num5)
{
// Local Definitions
   float TotalSum;
// Statements
   TotalSum = num1 + num2 + num3 + num4 + num5 ;
   return TotalSum;
} //sum

/* ==================== average ============================
This function finds the average of five numbers

*/

/*average (num1, num2, num3, num4, num5);
{

//Statements

float TotalSum;
TotalSum = num1 + num2 + num3 + num4 + num5 ;

average = sum / 5;  
printf("**In average result is: %6.2f\n", average);
 
  return average;
}*/






Last edited on
I'd love to help you but here are the problems.

1) you didn't use code tags or even bother to indent the program properly so it is difficult to read.

2) You didn't add specific enough comments for me to know which ones are causing you trouble.

The average function has no declaration yet so of course it can't be called from the main since the definition is a) wrong, b) comes after the main function. The function definitions also have to have the type before each arg.
Topic archived. No new replies allowed.