a guest Dec 11th, 2018 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- /* Program allows the user to input the length and width for
- a multiplication table and then displays one. However, the user cannot
- input more than 15 rows. */
- #include <iostream> // cout, cin, endl
- #include <iomanip> // setw, setprecision, align right
- #include <cstdlib> // system pause
- using namespace std;
- int main()
- // declare variables and constants
- int rows; // horizontal (width) of multiple table
- int cols; // vertial (length) of multiplication table
- // Prompt user for input
- // accept input from user. Accepts the width first and then length.
- cout << "Input the length and then the width of the multiplication table" << endl;
- cout << "Table cannot be bigger than 15 x 15 or less than 1 x 1. " << endl;
- cin >> cols >> rows;
- if(cols < 1 || rows < 1)
- cout << "Error: cannot enter 0 units for table length or width." << endl;
- } while(cols > 15 || rows > 15);
- // Output the table using for loops, one nested in the other.
- cout << right; // Aligns everything to the right.
- for (int i = 1; i <= rows; i++)
- for(int j = 1; j <= cols; j++)
- cout << setw(4) << i * j; // sets the width of 4 between each i*j
- cout << endl; // After each iteration of the nested loop, it will go to a new line.
- // Exit the program
- return 0;
RAW Paste Data