-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtraining3_1.cpp
More file actions
54 lines (52 loc) · 990 Bytes
/
training3_1.cpp
File metadata and controls
54 lines (52 loc) · 990 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
#include<iostream>
typedef struct Animal{
int name;
int age;
int health;
int food;
int clean;
} Animal;
void newAnimal(Animal& a,int num){
a.name = num;
a.age = 1;
a.health=10;
}
void play(Animal& a){
a.age+=1;
a.health-=1;
}
void show_stat(Animal& a){
std::cout
<< a.name<<" "
<< a.age <<" "
<< a.health <<std::endl;
}
int main(){
Animal* list[30];
int input;
int num=0;
while(1){
std::cout <<"입력:"<<std::endl;
std::cin>>input;
if(input == 0){
list[num] = new Animal;
newAnimal(*list[num],num);
num++;
}
else if(input == 1){
for (int i = 0; i < num; i++)
{
play(*list[i]);
}
}
else if(input == 2){
for (int i = 0; i < num; i++)
{
show_stat(*list[i]);
}
}
else{
break;
}
}
}