forked from manisha069/HacktoberFest21
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created a High Low guessing game in cpp
- Loading branch information
1 parent
fa9756d
commit 3ced496
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"files.associations": { | ||
"iostream": "cpp" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |