Well, does your program assume the person is going to enter five grades? If not you will want to use a "for" loop for this it will cut down on a majority of the code needed. I'll give you a quick skeleton. Also your >100 statement means that bonus points would be considered invalid.
#include <iostream>
int main()
{
int nGrades;
int grade;
int avg;
cout<<"Please enter in a grade no lower than 0'<<endl;
cout<<"Enter in -1 to end the program if you have less than 5 grades"<<endl;
for (nGrades=0;nGrades<=5;nGrades++)// Tells(Initial Value;The condition;and increment
or How much to increase the value per time for loop is repeated)
{
cin>>grade
if (grade==-1) //your sentinal value to allow the person to calculate if they have less than 5 grades
break;
}
calc avg
if (avg ...)
cout....
First, please use code tags: Edit your post, select all the code, then press the <> button on the right (under format). This makes it look much nicer, formats it properly and provides line numbers.
This bit:
sumofgrades += currentgrade;
is outside the loop, so your loop just keeps overwriting the currentgrade variable, and sets the sum variable to whatever the last currentgrade was, hence the F grade.
HTH
Edit:
With the naming of variables, I like to use CamelCase: as in NumberOfValidGrades, NumberOfInvalidGrades ; making it slightly easier to tell the difference between the two in this case. You could abbreviate a little & get rid of the Of: NumValidGrades, NumInvalidGrades. Readability is an important thing when writing code.
Initialising variables to something on declaration is usually a good idea (as giblit pointed out). it will save you one day. Sometimes zero is not a good choice, so one could pick a value that shows invalidity, but doesn't give misleading answers.
Yeah I just figured his loop would start at 0. I think the while loop doesn't even run. By default it is probably like 34k and the loop only runs when it is less than 5 and increments by one each time I figured he only wanted it to run 5 times so starting at 0 and going up by 1 each time but it could always start at 3 and end at 5 but it is hard to tell with the uninitialized value.
1 2 3 4 5 6
unsignedshortint numberofvalidgrades;
while (numberofvalidgrades < 5) //will never call the loop
{
//stuff
}
*Edit* I Think the op should learn to use proper indentations also.
1 2 3 4 5 6 7 8
int main()
{
short a( 3 );
if( a < 10 )
{
std::cout << a << std::endl;
}
}
^^ NOT the standard way to write and very hard to read.
1 2 3 4 5 6 7 8 9
int main()
{
short a( 3 );
if( a < 10 )
{
std::cout << a << std::endl;
}
}