OK, so I take it you want a 20 element array?
Code:
int numberarray[19];
This one holds 19 elements.
You then fill the array indexes 1..20:
Code:
numberarrayplace = 1;
do {
numberarray[numberarrayplace] = rand() % 99 + 1;
cout << numberarray[numberarrayplace] << " \n";
numberarrayplace = numberarrayplace + 1;
} while (numberarrayplace < 21);
When you only have 0..18...
That loop, by the way, should really be done as a for-loop. Using do - while is completely meaningless. And if you insist on using this loop-form, at least write numberarrayplace++ to add one to your current position.
Code:
numberrecalamount = 1;
memorycount = 0;
do {
cin >> numberrecal;
exitcheckloop = 0;
do {
if (numberarrayplace > 19) {
cout << "Incorrect! \n";
numberrecalamount = numberrecalamount + 1;
numberarrayplace = 0;
exitcheckloop = 1;
}
else if (numberarray[numberarrayplace] == numberrecal) {
memorycount = memorycount + 1;
cout << "Correct! \n";
numberarrayplace = 0;
numberrecalamount = numberrecalamount + 1;
exitcheckloop = 1;
}
else {
numberarrayplace = numberarrayplace + 1;
}
} while (exitcheckloop == 0);
} while (numberrecalamount < 20);
Now you check the elements from 1..19.
And again, it would be much clearer with a for-loop (using break to exit the loop), and at least using "variable++" where you increment something.
Code:
memorycount = 20;
memoryscore = 100 * (memorycount / 20);
You are not going to get much other than 100 out of this, are you?
But more importantly, if memorycount is not 20, then you'll always get zero, becuase x / y in integer math becomes zero if abs(x) < abs(y). Perhaps you would prefer to multiply memorycount by 100 first, then divide by the number of questions. That way, you get a "percentage number".
Edit: Kurt beat me to the last one.
--
Mats