-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ33.cpp
More file actions
105 lines (89 loc) · 1.87 KB
/
Q33.cpp
File metadata and controls
105 lines (89 loc) · 1.87 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
104
105
// 32.Write a program that categorizes a person’s age group based on the given age:
#include <iostream>
using namespace std;
void categorizeAgeGroup(int age) {
if (age < 13) {
cout << "Child" << endl;
}
else if (age >= 13 && age <= 19) {
cout << "Teenager" << endl;
}
else if (age >= 20 && age <= 59) {
cout << "Adult" << endl;
}
else if (age >= 60) {
cout << "Senior" << endl;
}
else {
cout << "Invalid age" << endl;
}
}
int main() {
int age;
cout << "Enter age: ";
cin >> age;
categorizeAgeGroup(age);
return 0;
}
#include <iostream>
using namespace std;
int ageCategory = -1;
void categorizeAgeGroup(int age){
if (age < 13) {
ageCategory = 0;
}
else if (age >= 13 && age <= 19) {
ageCategory = 1;
}
else if (age >= 20 && age <= 59) {
ageCategory = 2;
}
else if (age >= 60) {
ageCategory = 3;
}
else {
ageCategory = -1;
}
switch(ageCategory) {
case 0:
cout << "Child" << endl;
break;
case 1:
cout << "Teenager" << endl;
break;
case 2:
cout << "Adult" << endl;
break;
case 3:
cout << "Senior" << endl;
break;
default:
cout << "Invalid age" << endl;
break;
}
}
int main() {
int age;
cout << "Enter age: ";
cin >> age;
categorizeAgeGroup(age);
return 0;
}
#include <iostream>
#include <string>
using namespace std;
string categorizesAgeGroup(int age) {
return (age >= 0 && age <= 12) ? "Child" :
(age >= 13 && age <= 19) ? "Teenager" :
(age >= 20 && age <= 59) ? "Adult" :
(age >= 60) ? "Senior" :
"Invalid age";
}
int main() {
int age;
cout << "Enter age: ";
cin >> age;
string category = categorizesAgeGroup(age);
cout << "The person is a " << category << "." << endl;
return 0;
}