Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a funny algorithm in cpp #1237

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions jokes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main() {
// Seed the random number generator with the current time
srand(time(0));

// Array of jokes
string jokes[] = {
"Why did the scarecrow win an award? Because he was outstanding in his field!",
"I'm reading a book on anti-gravity. It's impossible to put down!",
"Why don't scientists trust atoms? Because they make up everything!",
"Parallel lines have so much in common. It's a shame they'll never meet.",
"What do you get when you cross a snowman and a dog? Frostbite!",
"Did you hear about the mathematician who's afraid of negative numbers? He'll stop at nothing to avoid them!",
"I used to play piano by ear, but now I use my hands.",
"Why did the bicycle fall over? Because it was two-tired!",
};

int numJokes = sizeof(jokes) / sizeof(jokes[0]);

while (true) {
// Generate a random index to select a joke
int randomIndex = rand() % numJokes;

// Display the random joke
cout << "Joke of the day: " << jokes[randomIndex] << endl;

// Pause for a moment before showing the next joke
cout << "Press Enter for another joke...";
cin.ignore();
}

return 0;
}