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

number guessing game using cpp #495

Closed
wants to merge 1 commit into from
Closed
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
30 changes: 30 additions & 0 deletions C++/NumberGuessing_Game.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// MADE BY LOVE -- KUNAL :)

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
int num, guess, tries = 0;
srand(time(0)); //seed random number generator
num = rand() % 100 + 1; // random number between 1 and 100
cout << "Guess My Number Game\n\n";

do
{
cout << "Enter a guess between 1 and 100 : ";
cin >> guess;
tries++;

if (guess > num)
cout << "Too high!\n\n";
else if (guess < num)
cout << "Too low!\n\n";
else
cout << "\nCorrect! You got it in " << tries << " guesses!\n";
} while (guess != num);

return 0;
}