Skip to content

Commit

Permalink
Created a High Low guessing game in cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
sid-khuntwal committed Oct 1, 2021
1 parent fa9756d commit 3ced496
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"iostream": "cpp"
}
}
47 changes: 47 additions & 0 deletions HighLowGame.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
int guess;
int compNum;
int counter;
srand(time(0));//seed
char choice;
bool game = true;

do{
compNum = (rand() % 1000) + 1;
counter = 1;
do {
cout << "Enter a number between 1 - 1000" << endl;
cin >> guess;

if (guess > compNum) {
counter++;
cout << "Too High." << endl;
}
else if (guess < compNum) {

counter++;
cout << "Too Low." << endl;
}
if (guess == compNum) {
cout << "You won! The computer number is " << compNum << "."
<< " You did it in " << counter << " tries." << endl;
cout << "Press 'q' or 'Q' to quit" << endl;
cin >> choice;
}

} while (guess != compNum);
if (choice == 'Q' || choice == 'q') {
game = false;
break;
}
} while (game !=false);

return 0;
}

0 comments on commit 3ced496

Please sign in to comment.