No, not really.
First of all, this is wrong:
else if (num1<=99>90 || ...
This doesn't do what you think it does. You really want this:
else if ((num1<=99 && num1>90) || ...
. You need to compare num1 against 99 and 90 separately.
Second, you don't do anything with values that are multiples of 10. You check for <= 99 but > 90. Nothing is done with 90.
Third, even if your comparison logic were correct, this is wrong:
1 2
|
else if (<num1 in range> || <num2 in range> || <num3 in range> ...)
counter++;
| |
You are processing all of the values at once. If any of them are in the range, the counter is incremented. No matter how many are in the range, the counter is only incremented 1 time. You need to process all of the values separately. You need to check num1 against all of the ranges, then num2, etc.
This would be a whole lot easier if you used an array (or better yet a std::vector) with 10 elements and then used a loop to check each value within a single block of code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
const int TOTAL = 10;
int num[TOTAL];
for (int i = 0; i < TOTAL; i++)
{
num[i] = (rand() % 50) + 50;
}
for (int i = 0; i < TOTAL; i++)
{
if (num[i] == 100)
{
hundred++;
}
else if (num[i] >=90)
{
ninety++;
}
//etc.
}
| |
Edit: Corrected typo in line 2 of the code
Edit 2: I just realized that you are not getting all of the values that you want.
(rand() % 50)
will give you a value between and including 0 - 49. When you add this to 50, you will never get 100.