๐ฎ Project 1: Multiplication Quiz Game
๐ Objective:
Create a terminal-based game that generates 5 random multiplication questions for the user. The user's score is tracked and shown at the end.
✅ Features:
-
Asks 5 random multiplication questions (1–10 range).
-
Uses a
for
loop for question repetition. -
Scores the user based on correct answers.
-
Provides instant feedback.
๐ Tools:
-
Language: C++
-
IDE: Code::Blocks / Visual Studio / VS Code / Terminal
-
Headers used:
<iostream>
,<cstdlib>
,<ctime>
๐ง Concepts Used:
-
for
loops -
if-else
statements -
Random number generation
-
User input/output
๐ค Source Code:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
srand(time(0)); // Seed the random number generator
int score = 0;
cout << "๐ฏ Welcome to the Multiplication Quiz Game!\n";
for (int i = 1; i <= 5; i++) {
int a = rand() % 10 + 1;
int b = rand() % 10 + 1;
int userAnswer;
cout << "Q" << i << ": What is " << a << " x " << b << "? ";
cin >> userAnswer;
if (userAnswer == a * b) {
cout << "✅ Correct!\n";
score++;
} else {
cout << "❌ Wrong. Correct answer is " << a * b << ".\n";
}
}
cout << "\n๐ Quiz finished! You scored: " << score << "/5\n";
return 0;
}
๐ Output Example:
๐ฏ Welcome to the Multiplication Quiz Game!
Q1: What is 4 x 7? 28
✅ Correct!
Q2: What is 3 x 8? 24
✅ Correct!
Q3: What is 2 x 9? 18
✅ Correct!
Q4: What is 10 x 1? 11
❌ Wrong. Correct answer is 10.
Q5: What is 5 x 2? 10
✅ Correct!
๐ Quiz finished! You scored: 4/5
๐ Learning Outcome:
-
How to generate random numbers using
rand()
. -
Practice using loops and conditionals.
-
Build logic for feedback and scoring.
๐ฎ Project 2: Guess the Number Game
๐ Objective:
Create a guessing game where the user must guess a number between 1 and 100 selected randomly by the computer.
✅ Features:
-
Random number generated between 1 and 100.
-
User guesses until correct.
-
Tells the user if their guess is too high or too low.
-
Tracks number of attempts.
๐ Tools:
-
Language: C++
-
Headers:
<iostream>
,<cstdlib>
,<ctime>
๐ง Concepts Used:
-
while
loop -
if-else
logic -
Random number generation
-
User input/output
๐ค Source Code:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
srand(time(0)); // Initialize random seed
int secret = rand() % 100 + 1; // Secret number between 1 and 100
int guess;
int tries = 0;
cout << "๐ฏ Welcome to 'Guess the Number'!\n";
cout << "I'm thinking of a number between 1 and 100...\n";
while (true) {
cout << "๐ Enter your guess: ";
cin >> guess;
tries++;
if (guess == secret) {
cout << "๐ Correct! You guessed it in " << tries << " tries.\n";
break;
} else if (guess < secret) {
cout << "๐ Too low. Try again.\n";
} else {
cout << "๐ Too high. Try again.\n";
}
}
return 0;
}
๐ Output Example:
๐ฏ Welcome to 'Guess the Number'!
I'm thinking of a number between 1 and 100...
๐ Enter your guess: 50
๐ Too low. Try again.
๐ Enter your guess: 75
๐ Too high. Try again.
๐ Enter your guess: 62
๐ Correct! You guessed it in 3 tries.
๐ Learning Outcome:
-
Build logical decision structures.
-
Learn how loops can repeat until a condition is met.
-
Understand user interaction with feedback.