Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //http://pastebin.com/u/TheWhiteFang
- //Tutorial 2 Section A part C
- #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;
- for (i = 0; i < value; i++)
- {
- for (j = 0; j < value; j++)
- {
- if (i == 0 || i == (value - 1) || j == 0 || j == (value - 1)) // ||- logical or //if j is first or last value, print * //if checks for true false in statement
- {
- cout << "* ";
- }
- else //this will happen if it is either not 1st value or last value
- {
- cout << " ";
- }
- }
- 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
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement