Oct 25, 2012 at 11:07pm UTC
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 Oct 25, 2012 at 11:08pm UTC
Oct 25, 2012 at 11:27pm UTC
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 Oct 25, 2012 at 11:28pm UTC
Oct 25, 2012 at 11:59pm UTC
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 Oct 26, 2012 at 12:00am UTC