0% found this document useful (0 votes)
19 views1 page

June 10 Home

This C++ program implements a simple guessing game where the user attempts to guess a randomly selected number from an array of three random numbers between 0 and 9. The user is prompted to enter their name and make guesses, with feedback provided for each guess. The game continues until the user guesses the correct number, at which point the total number of attempts is displayed.

Uploaded by

kashif m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views1 page

June 10 Home

This C++ program implements a simple guessing game where the user attempts to guess a randomly selected number from an array of three random numbers between 0 and 9. The user is prompted to enter their name and make guesses, with feedback provided for each guess. The game continues until the user guesses the correct number, at which point the total number of attempts is displayed.

Uploaded by

kashif m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <iostream>

#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand(time(0));
int arr_size = 3;
int secret_num[arr_size];
string name;
int guess;
int tries = 0;
for (int i = 0; i < arr_size; ++i) {
secret_num[i] = rand() % 10;
}
int randomNumber = secret_num[rand() % arr_size];
cout<< "*********Welcome to the Guessing Game!**********"<<endl;
cout<<"enter your name:";
getline(cin,name);
cout<<endl;
do
{
tries++;
cout << "Enter your guess: ";
cin >> guess;
if (guess == randomNumber) {
cout << "Congratulations!: "<<guess <<endl ;
}
else if (guess > 9){
cout<<"Number is invalid"<<endl;
}
else {
cout << "Your number does not match"<<endl ;
}
}
while (guess != randomNumber);
cout << "Number of tries: " << tries << endl;
return 0;
}

You might also like