Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int value = 0;
- while (1){
- cout << "Enter a number between 1 & 20: ";
- while (!(cin >> value)){
- cout << "Ending program. only integer values between 1 and 20 accepted" << endl;
- cin.clear(); //clear internal error flags
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- return 0;
- }
- if (value > 0 && value <= 20){
- int i = 0; int j = 0;
- int count = 1;
- for (i = 0; i < value; i++)
- {
- for (j = 0; j < value; j++)
- {
- cout << count << "\t";
- count++;
- }
- cout << endl;
- }
- }
- else{
- cout << "Ending program. Only integer values between 1 to 20 are accepted ";
- cout << endl; //cout << "\n"
- return 0; //this will end the program if wrong input is given
- cout << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement