Hi im new to C++ and we are making a program in my class to loop an If Else statement.
I'm having trouble getting the valid/invalid percentage as when the program finishes all it outputs is 0.00%.
Help would be appreciated
avg=(exam1+exam2+exam3)/3;
if((id<=maxid)&&(id>=minid)&&(exam1<=maxexam)&&(exam1>=minexam)&&(exam2<=maxexam)&&(exam2>=minexam)&&(exam3>=minexam)&&(exam3<=maxexam))
{
if(avg>=minpass)
{
validCount=validCount+1;
passCount=passCount+1;
examSum=examSum+avg;
outFile<<id<<setw(15)<<name<<setw(10)<<exam1<<setw(11)<<exam2<<setw(11)<<exam3<<setw(10)<<avg<<setw(10)<<"Passed"<<endl;
}
else
{
validCount=validCount+1;
failCount=failCount+1;
examSum=examSum+avg;
outFile<<id<<setw(15)<<name<<setw(10)<<exam1<<setw(11)<<exam2<<setw(11)<<exam3<<setw(10)<<avg<<setw(10)<<"Failed"<<endl;
}
}
else
{
invalidCount=invalidCount+1;
outFile<<id<<setw(15)<<name<<setw(10)<<exam1<<setw(11)<<exam2<<setw(11)<<exam3<<setw(10)<<"~~Invalid Data~~"<<endl;
}
inFile>>name>>id>>exam1>>exam2>>exam3;
}
int count=validCount+invalidCount;
float examMean=examSum/validCount;
float invalidPer=(invalidCount/count)*100;
float validPer=(validCount/count)*100;
outFile<<"Mean of AVG of Exams= "<<examMean<<endl<<endl;
outFile<<"Invalid data: "<<invalidPer<<"%"<<endl;
outFile<<"Valid data: "<<validPer<<"%"<<endl<<endl;
outFile<<"Number of Passed: "<<passCount<<endl;
outFile<<"Number of Failed: "<<failCount<<endl;
outFile<<"*<end>*"<<endl;
return 0;
}
code tags. It is infanately easier to read/diagnose with code tags.
[/code]
Last edited on