-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathargfunc.cpp
More file actions
39 lines (39 loc) · 1 KB
/
Copy pathargfunc.cpp
File metadata and controls
39 lines (39 loc) · 1 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
#include <iostream>
using namespace std;
void greet(string name, string greeting = "Hello", int times = 1) {
for (int i = 0; i < times; ++i) {
cout << greeting << ", " << name << "!" << endl;
}
}
int main() {
string name, greeting;
int choice, times;
cout << "Enter your name: ";
getline(cin, name);
cout << "\nChoose Greeting Type:\n";
cout << "1. Just Name (use default greeting and times)\n";
cout << "2. Name and Custom Greeting (use default times)\n";
cout << "3. Name, Custom Greeting, and Times\n";
cout << "Enter your choice (1-3): ";
cin >> choice;
cin.ignore();
if (choice == 1) {
greet(name);
}
else if (choice == 2) {
cout << "Enter your custom greeting (e.g., Hi, Welcome, Good Morning): ";
getline(cin, greeting);
greet(name, greeting);
}
else if (choice == 3) {
cout << "Enter your custom greeting: ";
getline(cin, greeting);
cout << "How many times do you want the greeting? ";
cin >> times;
greet(name, greeting, times);
}
else {
cout << "Invalid choice!" << endl;
}
return 0;
}