So, I'm trying to write a simple for loop, that will cycle through the first 6 variables in an array. However, in the code below, it doesn't cycle them, unless I change int a to equal 1; in which situation it works fine. That's fine by me, I'd just like to know why it doesn't work with a =0! Here is my code.
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
int Scores[36] = {};
void End()
{
using namespace std;
cout << "Enter your score for each individual value.\n";
cout << "Score 1: ";
cin >> Scores[1];
cout << Scores[1] << "\n";
cout << "Score 2: ";
cin >> Scores[2];
cout << Scores[2] << "\n";
cout << "Score 3: ";
cin >> Scores[3];
cout << Scores[3] << "\n";
cout << "Score 4: ";
cin >> Scores[4];
cout << Scores[4] << "\n";
cout << "Score 5: ";
cin >> Scores[5];
cout << Scores[5] << "\n";
cout << "Score 6: ";
cin >> Scores[6];
cout << Scores[6] << "\n";
cout << "The total is: " << Scores[1] + Scores[2] + Scores[3] + Scores[4] + Scores[5] + Scores[6] << endl;
int Hscore = 0;
for (int a = 0; Scores[a] > 8; a++)
Hscore++;
cout << "Total number of Hscore scored: " << Hscore << endl;
|
I've basically declared an array of 36 integers, all set to a value of 0. The user then enters a value for the first six integers in the array. The for loop should then check each number of the array, and if it is greater than 8, it increments the int Hscore.
But as I said, if a=0, nothing happens, it outputs int Hscore as having a value of zero. If I set a=1, then the int Hscore will give the correct value.
I'm sure I'm missing something simple. I know I obviously assign the first user value to Scores[1] instead of Scores[0], but the for loop should see that Scores[0] has a value of 0, ignore it and move on the Scores[1] then the rest of the array.
Also, add on question. Is there a way to limit it to only checking some of the array, not all 36 values?