well i think that this is correct but what i have face it that the program shut down automaticaly without seeing the result
#include<iostream>
#include<iomanip>
using namespace std; //program uses std;
double readInput(); //function prototype
void calculatetotals(double,double &,int &,double &,int &); //function prototype
void showresults(double,int,double,int); //function prototype
void starlines(void); //function prototype
int main()
{
double put=0;
double failmark=0; //fail mark
double passmark=0; //pass mark
int fail=0; //failing students
int pass=0; //passing students
put=readInput();
while (put!=-999)
{
calculatetotals(put,passmark,pass,failmark,fail);
put=readInput();
}
showresults(passmark,pass,failmark,fail);
return 0;
}
double readInput()
{
double mark;
cout<<"\nEnter student mark,-999 to stop : "; //prompt for student mark
cin>>mark; //reads mark
//the mark must not b = -999,musn't b -(<0) and musn't b >100(total mark).
while((mark!=-999 && mark<0)||mark>100)
{
cout<<"\nI think the test was out of 100..."<<endl; //if the user enters mark>50.
cout<<"\nStudent mark again please: "; //if wrong mark is entered
cin>>mark; //reads mark
}
return mark;
}
void calculatetotals(double mark,double &passmark,int &pass,double &failmark,int &fail)
{
if(mark>=0 && mark<50) // for students who failed(got below 50)
{
fail++; //failed students.
failmark+=mark; //fail mark.
}
if(mark>=50 && mark<=100) //for students who passed(got 50 and above ).
{
pass++; //passed students.
passmark+=mark; //pass mark.
}
}
void showresults(double Passmark,int Pass,double Failmark,int Fail)
{
cout<<fixed<<setprecision(2); //formatting the data type
cout<<endl;
cout<<"No. of students in a class : "<<Pass+Fail<<endl; //students in class
cout<<"\n\t\tResults :"<<endl;
starlines(); //call function starlines()
if(Pass!=0) //if pass = 0,is not calculated(average).
{
cout<<"\tPassed students : "<< Pass <<endl;
}
if(Fail!=0) //if fail = 0,is not calculated(average).
{
cout<<"\tFailed students : "<< Fail <<endl;
}
starlines(); //call function starlines()
cout<<"\n\t\tAverages :"<<endl;
starlines(); //call function starlines()
if(Pass != 0)
{
cout<<"\tPass average :"<<(Passmark/Pass)<<endl;
}
if(Fail != 0)
{
cout<<"\tFail average :"<<(Failmark/Fail)<<endl;
}
starlines(); //call function starlines()
cout << endl;
}
//definition of the function starline.
void starlines(void)
{
cout <<"\t*\a*\a*\a**************\a*\a*\a"<<endl;
cout <<endl;
}