Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <string>
- using namespace std;
- void playGame(int max, int min, int num) {
- cout << "Try to guess the secret number: ";
- int tryNum;
- cin >> tryNum;
- if (tryNum < num) {
- cout << "The secret number is bigger!\n";
- playGame(max, min, num);
- }
- else if (tryNum > num) {
- cout << "The secret number is smaller!\n";
- playGame(max, min, num);
- }
- else {
- cout << "Congratulations! You win this game! The secret number was " << num << endl;
- cout << "Do u want to play this game again? (yes/no): ";
- string str;
- cin >> str;
- if (str == "yes") {
- cout << "Okay, we chose new secret number!\n";
- num = min + rand() % (max - min + 1);
- playGame(max, min, num);
- }
- else {
- cout << "Okay! Goodbye!\n";
- }
- }
- }
- int main() {
- srand(time(NULL));
- int max;
- int min;
- cout << "Enter the minimum number of range: ";
- cin >> min;
- cout << "Enter the maximum number of range: ";
- cin >> max;
- int num = min + rand() % (max - min + 1);
- playGame(max, min, num);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement