#include "stdafx.h"
#include <iostream>
usingnamespace std;
int main()
{
int grade[13];
int outof[13];
int gradeTotal;
int outofTotal;
float finalGrade;
{
cout<<"Please Enter Your First Grade ";
cin>>grade[0];
cout<<"Out of ";
cin>>outof[0];
cout<<"Please Enter Your Second Grade ";
cin>>grade[1];
cout<<"Out of ";
cin>>outof[1];
cout<<"Please Enter Your Third Grade ";
cin>>grade[2];
cout<<"Out of ";
cin>>outof[2];
cout<<"Please Enter Your Fourth Grade ";
cin>>grade[3];
cout<<"Out of ";
cin>>outof[3];
cout<<"Please Enter Your Fifth Grade ";
cin>>grade[4];
cout<<"Out of ";
cin>>outof[4];
cout<<"Please Enter Your Sixth Grade ";
cin>>grade[5];
cout<<"Out of ";
cin>>outof[5];
cout<<"Please Enter Your Seventh Grade ";
cin>>grade[6];
cout<<"Out of ";
cin>>outof[6];
cout<<"Please Enter Your Eight Grade ";
cin>>grade[7];
cout<<"Out of ";
cin>>outof[7];
cout<<"Please Enter Your Ninth Grade ";
cin>>grade[8];
cout<<"Out of ";
cin>>outof[8];
cout<<"Please Enter Your Tenth Grade ";
cin>>grade[9];
cout<<"Out of ";
cin>>outof[9];
cout<<"Please Enter Your Eleventh Grade ";
cin>>grade[10];
cout<<"Out of ";
cin>>outof[10];
cout<<"Please Enter Your Twelth Grade ";
cin>>grade[11];
cout<<"Out of ";
cin>>outof[11];
cout<<"Please Enter Your Thirtheenth Grade ";
cin>>grade[12];
cout<<"Out of ";
cin>>outof[12];
gradeTotal=(grade[0]+
grade[1]+
grade[2]+
grade[3]+
grade[4]+
grade[5]+
grade[6]+
grade[7]+
grade[8]+
grade[9]+
grade[10]+
grade[11]+
grade[12]);
outofTotal=(outof[0]+
outof[1]+
outof[2]+
outof[3]+
outof[4]+
outof[5]+
outof[6]+
outof[7]+
outof[8]+
outof[9]+
outof[10]+
outof[11]+
outof[12]);
finalGrade=gradeTotal/outofTotal*100;
cout<< " Your grade is "<<finalGrade<<endl;
}
system ("Pause");
return 0;
}
Can someone help me I can't seem to figure out why ever time I input all of my grades it give me my grade as 0? Thanks
finalGrade=gradeTotal/outofTotal*100;
You're dividing two integers, which will always give an integer result.
(e.g. 50/100 = 0, although 50.0/100 = 0.5)
Easiest way to fix that is to cast one of them to float. finalGrade = ((float)gradeTotal) / outofTotal * 100;