Hello DJM34,
Not sure where you went wrong with your code tags, but this might help
http://www.cplusplus.com/articles/z13hAqkS/
If this is an assignment for school please post the instructions that you were given, This will help everyone know what you have to do without having to guess.
The first thing I see is that you should initialize you variables when defined. It is always nice to know that they do not contain a garbage value.
This code does not make any sense.
1 2 3 4 5 6
|
cout << " Enter number of students: ";
cin >> Numstudents;
cout << endl;
cout << " Enter student's name: ";
cin >> name;
|
If you enter 5 for "numStudents" you are saying the you are only using 1 name for all 5 students. Or am I misunderstanding this?
In the while loop:
while (counter < Numstudents)
first time through this works. Once inside the loop first you have
counter += score;
then at the ens of the loop you have
counter++;
.
Next check of the while condition "counter" will most likely be greater than 5 and cause the condition to fail. When you say
counter += score;
did you mean to use a different variable?
In the for loop
for (int test = 1; test <= 10; test++)
the 10 should be "numStudents" because this could be less than 10 or greater.
The line
studentavg = score / 10;
. "studentavg" is defined as an int, but "score" is defined as a "double" the 10 is considered an "int", but will be promoted to a "double" for the calculation. The you are trying to stuff a "double" into an "int" which will store the whole number and drop the decimal part. not what you want. Just be the name "studentavg" one would think that this would be a "double" unless your intent is to use "int"s.
I have not run the program yet, but I think that the if/else if statements will work.
Andy