-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
104 lines (82 loc) · 1.69 KB
/
Copy pathmain.cpp
File metadata and controls
104 lines (82 loc) · 1.69 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//GuessMyNumber - The classic number guessing game
#include <iostream>
using namespace std;
void HalfPyramid() {
int rows;
int printType;
cout << "Enter number of rows: ";
cin >> rows;
cout << "Print with numbers(1) or *(2): ";
cin >> printType;
cout << "\n";
for(int i = 1; i <= rows; ++i) {
for(int j = 1; j <= i; ++j) {
if(printType == 1) {
cout << j;
} else {
cout << "*";
}
}
cout << "\n";
}
}
void InvertedHalfPyramid() {
int rows;
int printType;
cout << "Enter number of rows: ";
cin >> rows;
cout << "Print with numbers(1) or *(2): ";
cin >> printType;
cout << "\n";
for(int i = rows; i > 1; i--) {
for(int j = 1; j <= i; ++j) {
if(printType == 1) {
cout << j;
} else {
cout << "*";
}
}
cout << "\n";
}
}
void Pyramid() {
int space, rows;
cout << "Enter number of rows: ";
cin >> rows;
cout << "\n";
for(int i = 1, k = 0; i <= rows; ++i, k = 0) {
for(space = 1; space <= rows - i; ++space) {
cout << " ";
}
while(k != 2 * i - 1) {
cout << "* ";
++k;
}
cout << endl;
}
}
int main() {
int selection;
cout << "Welcome to Too Many Examples :D\n\n";
cout << "Choose an example : \n";
cout << "1 - Print half pyramid with numbers or *\n";
cout << "2 - Print inverted half pyramid with number or *\n";
cout << "3 - Print pyramid *\n";
cin >> selection;
// while (selection != 0) {
switch (selection) {
case 1:
HalfPyramid();
break;
case 2:
InvertedHalfPyramid();
case 3:
Pyramid();
break;
default:
break;
}
//}
cout << "\n\n\t!!DONE!!\n\n";
return 0;
}