-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXmasTree.cpp
More file actions
69 lines (48 loc) · 999 Bytes
/
XmasTree.cpp
File metadata and controls
69 lines (48 loc) · 999 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
using namespace std;
int getInt();
int main(){
int step, width, space, root;
cout << "단 수를 입력하세요.(1에서 50 사이 정수):";
while(true){
step = getInt();
if(step>=1 && step<=50) break;
cout << "1에서 50사이로 다시 입력하세요.:";
}
width = 2*step + 3;
for(int i=1; i<=step; i++){
space = width/2;
for(int j=1; j<=i+2; j++){
for(int k=1; k<=space; k++) cout << " ";
for(int l=1; l<=2*j-1; l++) cout << "*";
space=space-1;
cout << endl;
}
}
root = width/2;
for(int j=1; j<=root; j++){
for(int k=1; k<=root; k++) cout << " ";
cout << "*";
cout << endl;
}
return 0;
}
int getInt(){
int num;
float f;
cin >> f;
if(cin.fail()){
cout << "문자 말고 정수를 입력하세요.:";
cin.clear();
cin.ignore();
return getInt();
}
else{
num = static_cast<int>(f);
if(static_cast<float>(num) != f){
cout << "실수 말고 정수를 입력하세요.:";
return getInt();
}
else return num;
}
}