Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

cout << \" How many students are there?\" << endl; cin >> numStudents; while (nu

ID: 3684784 • Letter: C

Question

cout << " How many students are there?" << endl;
cin >> numStudents;
while (numStudents <= 0) {
   cout << "Sorry! Please enter a valid positive integer!" << endl << endl;
   cout << " How many students are there?" << endl;
   cin >> numStudents;

I'm using Visual Studio for C++.

If a letter or character other than a positive integer is input, it breaks the code.

My teacher is only requiring us to omit letters from A to z, not all characters.

this is what my code looks like right now, but im wondering how i would omit letters from breaking the code.
would i able to do another while statement? or a switch statement? I would need to omit everything from 'A' to 'z'
I just dont know how. please help!

Explanation / Answer


if ( !isUpper ( numStudents ) ) { // If input is not in A to Z then do else retry
your while loop
{

// Your operation on numStudents   

}
} else {
cout << " Please enter correct value " << endl;
cin >> numStudents;
}