(Please Help)Pass or Fail with Percentages

I'm trying to get how many student pass and fail along with the percentage of students passing and failing. Any and all help is appreciated.

#include<iostream>
using namespace std;
int main()
{
char grades;
int passing = 0, failing = 0, total = 0;
double gpa = 0.0, passingPercent = 0.0, failingPercent = 0.0;
while (gpa>5){
cout<< "Enter all your grades, Z terminates the list" << endl;
cin >> grades;
if (grades = 'a' || 'b' || 'c' || 'd'){
passing++;
gpa += 4.0;}
else if (grades = 'f'){
failing++;
}
else if (grades = 'z'){
break;
}
}
total = passing + failing;
if (total > 0)
{passingPercent = (passing / total) * 1.0;
failingPercent = (failing / total) * 1.0;
gpa = (gpa / total) * 1.0;
}
cout << "Students passing: " << passing << "(" << passingPercent << ")" << endl;
cout << "Students failing: " << failing << "(" << failingPercent << ")" << endl;
system("pause");

return(0);
}
Last edited on
The while loop will never be executed because the initial value of gpa is less than 5

double gpa = 0.0, passingPercent = 0.0, failingPercent = 0.0;
while (gpa>5){

This

if (grades = 'a' || 'b' || 'c' || 'd'){

is assigning 1 to grades. I think you meant

if (grades == 'a' || grades == 'b' || grades == 'c' || grades == 'd'){

It is not clear what the statement below is doing

gpa += 4.0;}

Again instead of the comparision you use the assignment opeartor here

else if (grades = 'f'){

and here

else if (grades = 'z'){

As far as I know persent is calculated by multiplying an expression by 100. Why do you use 1.0 instead of 100.0?

{passingPercent = (passing / total) * 1.0;
failingPercent = (failing / total) * 1.0;

This statement again is unclear

gpa = (gpa / total) * 1.0;

Last edited on
My percents still don't work but the rest does now. Any ideas?
#include<iostream>
using namespace std;
int main()
{
char ch1='a', ch2='b', ch3='c', ch4='d', ch5='e', ch6='f', ch7='z';
char ch;
int passing = 0, failing = 0, total = 0;
double gpa = 0.0, passingPercent = 0.0, failingPercent = 0.0;
//while (gpa=gpa){

do {
cout<< "Enter all your grades, Z terminates the list" << endl;
cin >> ch;
if ( ch == ch1 || ch == ch2 || ch == ch3 ||ch == ch4){
passing++;
}
else if (ch == ch5 || ch == ch6){
failing++;
}
}while(ch!= ch7);
total = passing + failing;
if (total > 0){
passingPercent = ((passing / total) * 100.0);
failingPercent = ((failing / total) * 100.0);
}
cout << "Students passing: " << passing << "(" << passingPercent << ")" << endl;
cout << "Students failing: " << failing << "(" << failingPercent << ")" << endl;
system("pause");

return(0);
}
Last edited on
Topic archived. No new replies allowed.