### Beginner Help

How do I make this code to where if a user entered credits that are less than 0 and greater than 100 as Invalid? Then repeat and as the question How many credit hours do you have? I don't know how to make it repeat saying invalid until the user enters the right amount of credits then ask the question again.

 ``1234567891011121314151617181920212223242526272829`` ``````#include using namespace std; int main() { int credit; cout << "How many credit hours do you have?" << endl; cin >> credit; While (credit <= 0 || credit >= 100); cout << "Answer is Invalid, Try Again!" << endl; if (credit < 32) cout << "You are a Freshman" << endl; else if (credit >= 32 && credit <= 63) cout << "You are a Sophomore" << endl; else if (credit >= 64 && credit <= 95) cout << "You are a Junior" << endl; else if (credit >= 95) cout << "You are a Senior" << endl; return 0; }``````

Last edited on
You could use a do while loop. It would look something like this.
 ``12345`` ``````do { cout << "How many credit hours do you have?" << endl; cin >> credit; }while(credit > 0 && credit <100);``````
The 11th line makes no sense. The W in `while` should be lowercase, and you shouldn't have that `;` at the end. Also you'll need another `cin` in the while block in order to query the user again, otherwise the `cout << "Answer is Invalid, Try Again!" << endl;` line would repeat forever.

 ``12345678910111213141516171819202122`` ``````#include using namespace std; int main() { int credit; cout << "How many credit hours do you have?" << endl; cin >> credit; while (credit <= 0 || credit >= 100) { cout << "Answer is Invalid, Try Again!" << endl; cin >> credit; } if (credit < 32) cout << "You are a Freshman" << endl; else if (credit >= 32 && credit <= 63) cout << "You are a Sophomore" << endl; else if (credit >= 64 && credit <= 95) cout << "You are a Junior" << endl; else if (credit >= 95) cout << "You are a Senior" << endl; return 0; }``````
Ok, thanks for the feedback I''ll be sure to adjust my code. Appreciate the help a lot.