Write a small c++ program to validate user input is within a range
#include <iostream> using namespace std; int main() { int num; do { cout << "Enter a number(between 1 and 100): "; cin >> num; } while (num < 1 || num > 100); cout << "You entered " << num << endl; return 0; } /* If a non-numeric data is entered, then the program keeps on prompting for input forever and does not read any other input. so, essentially program does not work properly. */
Get Answers For Free
Most questions answered within 1 hours.