-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask3.cpp
More file actions
27 lines (25 loc) · 1.05 KB
/
Task3.cpp
File metadata and controls
27 lines (25 loc) · 1.05 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
//CS211 Lab 7
//Task 3
//Max Davy
#include <iostream>
#include <string>
#include <random>
#include <ctime>
using namespace std;
/*Task 3:
Create a "Digital Fortune Cookie" program. The user types their name, and the program returns a
randomly selected fortune message personalized with their name.
Requirements:
• Use cin and cout for user interaction.
• Store 5+ different fortune messages in a string array.
• Use the rand() function to pick one at random.
• Display the message with the user's name.*/
const string fortunes[5]={"You will have a great day tomorrow","You are doomed","Beware of falling refrigerators on May 9th","Seek for the sign of the marmoset and great wealth will come to you","''Interesting, this is not'' - Yoda"};
int main() {
string name;
cout<<"What is your name?\n";
cin>>name;
srand((unsigned int)time(NULL));//seed random number generator with time otherwise the answer will be the same each time the program is run
cout<<name<<", your very special and unique fortune is: "<<fortunes[rand()%5]<<endl;
return 0;
}