-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
173 lines (170 loc) · 5.76 KB
/
main.cpp
File metadata and controls
173 lines (170 loc) · 5.76 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include<iostream>
#include<ctime>
#include<cstdlib>
#include<fstream>
#include<vector> // Added missing include
using namespace std;
// To greet the user
void greet(string name) {
cout <<"Hello "<<name<<"! I'm your Virtual Assistant."<< endl;
}
// Asking for the time
void displayTime() {
time_t current = time(0); // Get the current time
tm *timeInfo = localtime(¤t); // Convert to local time
int hrs = timeInfo->tm_hour;
int mins = timeInfo->tm_min;
cout << "Current Time: " << hrs << ":";
if (mins < 10) {
cout << "0";
}
cout << mins <<endl;
}
// Asking for the date
void showDate() {
time_t now = time(0);
tm *ltm = localtime(&now);
cout << "Today's Date: ";
int year = 1900 + ltm->tm_year;
int month = 1 + ltm->tm_mon;
int day = ltm->tm_mday;
cout << year << "/" << month << "/" << day << endl;
}
// Requesting a Joke
void tellJoke() {
string jokes[] = {
"Why don't skeletons fight each other? Because they don't have the guts.",
"Why did the computer get cold? Because it forgot to close its Windows.",
"I told my computer I needed a break, and it said 'No problem, I'll go to sleep!'",
"Why don't scientists trust atoms? Because they make up everything!",
"I'm on a seafood diet. I see food and I eat it.",
"Why was the math book sad? Because it had too many problems."
};
srand(time(0));
int index = rand() % 6;
cout << jokes[index] << endl;
}
// Function to ask a riddle
void askRiddle() {
string input;
cout << "Bot: Welcome! Let's solve a riddle." << endl;
cout << "Bot: Here’s your riddle:" << endl;
cout << "I’m something. The more of me you have, the less you can see. What am I?" << endl;
while (true) {
cout <<"You: ";
cin>>input; //to capture user input
if (input == "darkness" || input == "Darkness") {
cout <<"Assistant: Correct! Darkness is the answer."<< endl;
break;
}
else if (input == "bye") {
cout <<"Assistant: Goodbye! Have a great day!"<< endl;
break;
}
else {
cout <<"Assistant: Oops! Try again. Hint: It's the absence of light."<< endl;
}
}
}
// Asking "How's the weather?"
void weather() {
string weatherConditions[] = {
"It's raining cats and dogs. Grab an umbrella!",
"The sun is shining, but it's a bit windy.",
"It’s foggy outside, so drive carefully.",
"Heavy thunderstorms are expected. Stay indoors!",
"The temperature is mild and pleasant today.",
"It’s a hot day, make sure to stay hydrated!",
"It's cloudy and cool.",
"It's sunny and warm today!",
"Looks like it's going to rain. Carry an umbrella!",
"Stormy weather outside. Stay safe!",
"Chilly winds are blowing. Wear a jacket!",
"Perfect weather for a walk!"
};
srand(time(0));
int index = rand() % 12;
cout << weatherConditions[index] << endl;
}
// Function to get a list of fun facts
void printRandomFunFact() {
const char* facts[] = {
"Honey never spoils. Archaeologists found 3000-year-old honey and it was perfectly edible!",
"Bananas are berries, but strawberries are not!",
"Octopuses have three hearts!",
"A group of flamingos is called a 'flamboyance'.",
"There are more stars in the universe than grains of sand on Earth.",
"Butterflies can taste with their feet!",
"Sharks existed before trees!",
"The unicorn is the national animal of Scotland.",
"A day on Venus is longer than a year on Venus.",
"Sloths can hold their breath longer than dolphins can!"
};
const int numFacts = sizeof(facts) / sizeof(facts[0]);
srand(time(0)); // Seed the random number generator
int index = rand() % numFacts;
cout << "Fun Fact: " << facts[index] << endl;
}
// Function to perform the calculation
void calculator(){
double num1,num2;
char op;
cout<<"Simple Function-Based Calculator\n";
cout<<"Enter first number: ";
cin>>num1;
cout<<"Enter operator (+, -, *, /): ";
cin>>op;
cout<<"Enter second number: ";
cin>>num2;
cout<<"Result: ";
if(op == '+'){
cout<<num1 + num2<<endl;
} else if(op == '-'){
cout<<num1 - num2<<endl;
} else if(op == '*'){
cout<<num1 * num2<<endl;
} else if(op == '/'){
if(num2 != 0)
cout<<num1 / num2<<endl;
else
cout<<"Error: Division by zero!"<<endl;
} else{
cout<<"Invalid operator!"<<endl;
}
}
// Main function
int main() {
srand(time(0)); // Important to call srand once at start
string name;
cout << "Enter your name: ";
cin>>name;
greet(name);
string command;
while (true) {
cout << "\nHow can I help you, " << name << "? (type 'help' for options)\n> ";
cin>>command;
if (command == "time") {
displayTime();
} else if (command == "date") {
showDate();
} else if (command == "weather") {
weather();
} else if (command == "calculator") {
calculator();
}else if (command == "joke") {
tellJoke();
} else if (command == "funfact") {
printRandomFunFact();
} else if (command == "riddle") {
askRiddle();
} else if (command == "help") {
cout << "Available commands:\n";
cout << "- time\n- date\n- weather\n- calculator\n- joke\n- funfact\n- riddle\n- exit\n";
} else if (command == "exit") {
cout <<"Goodbye, "<<name<<"! Have a great day!"<<endl;
break;
} else {
cout<<"Sorry, I didn't understand that command."<<endl;
}
}
}