Menu Driven Program

design a program marks.cpp that will be used to analyse a list of marks. This program will be menu driven, and the user should be able to interactively enter or delete any marks, list all the marks, calculate their average

This is what the menu looks like

MAIN MENU
0. Exit
1. Add a student mark
2. List all student marks
3. Calculate the marks average


and this is what I have so far


#include<iostream>
using namespace std;

void runMenu();
bool addMark(double allMarks[], int &totalRec, double &mark);
int numericalMenu();
bool displayMarks(double allMarks[], int totalRec);
bool findMean(double allMarks[], int totalRec, double &mean);

int main()
{
runMenu();
system("pause");
return 0;
}




void displayMenu()
{
cout << "\n\n\
*** MAIN MENU\n\
0. Exit\n\
1. Add a student mark\n\
2. List all student marks\n\
3. Calculate the marks average\n\
4. Calculate the standard deviation\n\
5. Delete a student mark\n\
6. Find the number of students via a mark\n\
7. Display distinct marks and their occurrences\n\
* Your choice ->";

}
int numericalMenu()
{

int option=-1;
string word;
void displayMenu();

do
{
displayMenu();
cin.clear();
if(!(cin >> option))
{
if(!cin.eof())
{
cin.clear();
cin >> word;
}
continue;
}
}
while(option<0);
return option;
}
void runMenu()
{ int option;
do
{
const int NUMELS = 1;
int i, grade[NUMELS];
option=numericalMenu();
switch(option)
{
case 1:
for (i = 0; i < NUMELS; i++)
cout << "enter a grade";
cin>>grade[i];
break;

case 2:
cout <<"all the marks entered are:"<< grade[i]<<endl;
break;

}
}

while (option!=0);
}
okay the trouble I am having is when I enter a mark it saves it to the array. I then go to display it it will be there. When I enter another mark it will save it but when i go to display that it only displays the 2nd mark.
I also want a heads up on the average function

thanks
first, we'll get the formalities out of the way, learn how to use code tags, ref: http://www.cplusplus.com/forum/articles/42672/

op wrote:
okay the trouble I am having is when I enter a mark it saves it to the array. I then go to display it it will be there. When I enter another mark it will save it but when i go to display that it only displays the 2nd mark.

your problem's here:
1
2
3
case 2:
cout <<"all the marks entered are:"<< grade[i]<<endl;
break

use a loop to read the grade[i] values from the array and display them

op wrote:
I also want a heads up on the average function

read the grades one by one, add them and divide the summation by number of grades
Topic archived. No new replies allowed.