So the idea is to ask the user for each element of the array, but after an input is given for the first question (where it asks for the amount of elements), nothing happens. Can't figure out why.
#include <iostream>
int main()
{
int numGrades;
tryAgain:
std::cout << "Enter number of grades" << std::endl;
std::cin >> numGrades;
if (numGrades > 30)
{
std::cout << "Please enter a valid number of grades" << std::endl;
goto tryAgain;
}
int grades[numGrades - 1];
int gradeCount = 0;
while (gradeCount < numGrades);
{
std::cout << "Enter grade number" << gradeCount + 1 << ":";
std::cin >> grades[gradeCount];
++ gradeCount;
}
std::cout << grades;
return 0;
}
The constuction while (true);
means while (true) {}
(i.e. infinite loop).
So, when you write
while (gradeCount < numGrades);
{
// ...
}
you have the following:
while (gradeCount < numGrades)
{
}
{
// ...
}
Second block will never be executed if gradeCount < numGrades
.
You are using
while (gradeCount < numGrades);
with a semi-colon (;) at the end of this line so the next line will not exectue because the condition is always true as there is no increment or decrement in the respective variables.
In short just remove the (;)
while (gradeCount < numGrades)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With