forked from ChicoState/ai-cpp-container-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
45 lines (36 loc) · 896 Bytes
/
Copy pathmain.cpp
File metadata and controls
45 lines (36 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <iomanip>
#include <limits>
void printTable(long long limit) {
for (long long row = 1; row <= limit; ++row) {
for (long long column = 1; column <= limit; ++column) {
std::cout << std::setw(4) << row * column;
}
std::cout << '\n';
}
}
int main() {
long long number;
while (true) {
std::cout << "Enter a number from 1 to 12 (0 to exit): ";
if (!(std::cin >> number)) {
if (std::cin.eof()) {
break;
}
std::cout << "Please enter a whole number.\n";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
continue;
}
if (number == 0) {
std::cout << "Goodbye!\n";
break;
}
if (number < 1 || number > 12) {
std::cout << "Number must be between 1 and 12.\n";
continue;
}
printTable(number);
}
return 0;
}