Check out the red highlighter below, how can you sum the studentMark[MaxSize] for an average. For example (78.5 + 66 + 73 + 56.5 + 88.3 + 64.5 + 45 + 57) divides actualNum = average.
I've been figuring that one for hours!
#include <iostream>
#include <string>
using namespace std;
const int MaxSize = 100;
int actualNum = 8;
string studentID[MaxSize]={"p1001","p1002","s000101","s000102","s000135","s990001","s990002","s000103"};
double studentMark[MaxSize]={78.5, 66, 73, 56.5, 88.3, 64.5, 45, 57};
char studentGrade[MaxSize]={'D', 'C', 'C', 'P', 'H', 'P', 'F', 'P'};
void do_again(),direction(int ans);
void option_1(),option_2(),option_3(),option_4();
int main()
{
do_again();//call do_again function, say goodbye to main until everything else is done running
return 0;
}//end function
void do_again()
{
int ans;//declare ans variable, this will be used OVER AND OVER
do
{
cout << "MAIN MENU\n\n";
cout << "1. Exit ";
cout << "2. Statistics\n";
cout << "3. Enter mark ";
cout << "4. Find mark\n\n";
cout << "Please choose a number to enter: ";
cin >> ans;
while (cin.fail())
{cout << "\nWrong data type. Please re-enter: ";
cin.clear();
cin.ignore(80,'\n'); //Take in an answer
cin>>ans; cout<<endl;
}
direction(ans);//Send that answer to direction
}while(ans!=1);//Keep on keeping on until they press 1 to exit
}//end function
void direction(int ans)
{
switch (ans)//roll thru options
{
case 1: //if they picked the number 1, its gonna go to this function,
option_1();
break;
case 2:
option_2();
break;
case 3:
option_3();
break;
case 4:
option_4();
break;
default://THEY DID NOT READ THE MENU, WHO WOULD HAVE THOUGHT?
cout << "\nPlease press 2, 3 or 4. Press 1 for close the menu.\n\n\n";
//break;
}
}//end function
//functions, FILL WITH VALUABLE PROGRAMMING SKILLS
void option_1()
{
}//end function
void option_2()
{
cout << "\n\nSTATISTICS MENU\n\n";
cout << "The number of student records is " << actualNum << " and" << endl;
[B]double total;
float average;
total = studentMark[actualNum];
average = (total / actualNum);
cout << "the average of those student marks is " << average;
cout << "\n\n";[/B]
}//end function
void option_3()
{
double mark;
char grade;
string id;
cout << "\n\n";
cout << "ENTER MARK MENU\n\n";
cout << "Enter the ID: ";
cin >> studentID[actualNum];
cout << "Enter the mark: ";
cin >> mark;
studentMark[actualNum]=mark;
cout << "\n\n";
if (mark<=100 && mark>=0)
{
if (mark>=85)
// cout << "The mark " << mark << " is: H\n\n\n";
studentGrade[actualNum]='H';
else if (mark>=75)
// cout << "The mark " << mark << " is: D\n\n\n";
studentGrade[actualNum]='D';
else if (mark>=65)
// cout << "The mark " << mark << " is: C\n\n\n";
studentGrade[actualNum]='C';
else if (mark>=50)
// cout << "The mark " << mark << " is: P\n\n\n";
studentGrade[actualNum]='P';
else
// cout << "The mark " << mark << " is: F\n\n\n";
studentGrade[actualNum]='F';
}
else
studentGrade[actualNum]='I'; // Error
++actualNum;
}//end function
void option_4()
{
int i=-1;
string id;
cout << "\n\n";
cout << "FIND MARK MENU\n\n";
cout << "Enter your student ID: ";
cin >> id;
while(++i<actualNum) {
if(id==studentID[i])
{cout << "Your mark is: " << studentMark[i] << " and your grade is: " << studentGrade[i];
cout << "\n";
break;}
}
if (i==actualNum)
cout << "Sorry, it is not existing." << endl;
cout << "\n\n";
} //end function