First you need to decide the input format.
What if I entered '988712634485' Assuming your program would take care of spacing the numbers.? Would that be the same as, '98 87 12 63 44 85' or what if the true grades were '98, 87, 12, 63, 44, 8, 5'. You need to first tell the user how to enter the grades.
After you have done this, if you have things like spaces, that would account in your strlen().
A simpler way to do it is to increment your size variable inside of a loop that will receive the grades. If you need to delete a grade, just decrement the size variable.
Assuming these are grades, they cannot be negative, and are between 0-100 +/- extra credit.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
int grades[100];
int size = 0;
while (/*loop condition*/)
{
int tempGrade;
cout << "Enter the grades, if you would like to stop entering grades enter -1 at any time";
//input grade
if (tempGrade == -1)
{
// leave loop
}
else{
// Place tempGrade at grades[size]
// Increment size;
}
}
cout << "Your numbers are ";
for (int i = 0; i < size; i++)
{
cout << grades[i] << endl;
}
}
|
This is assuming you are being mandated to use an array.