Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include <array>
- #include <random>
- #include <math.h>
- int minimum = 0;
- int maximum = 0;
- bool doesUserWantsToPlay()
- {
- bool rResult = false;
- std::cout << "Guess the number game" << std::endl;
- while (true)
- {
- std::cout << "Do you want to play? (1 - yes, 0 - no):";
- std::string answer;
- std::cin >> answer;
- if ((answer == "1") || (answer == "0"))
- {
- rResult = (answer == "1");
- break;
- }
- std::cout << "Sorry, I did not understand." << std::endl;
- }
- return rResult;
- }
- void getInterval() {
- std::cout << "enter the interval " << std::endl;
- std::cout << " enter the start point" << std::endl;
- std::cin >> minimum;
- std::cout << " enter the end point " << std::endl;
- std::cin >> minimum;
- if (maximum < minimum)
- {
- int temp;
- temp = maximum;
- maximum = minimum;
- minimum = temp;
- }
- }
- int getRandomNumber() {
- static std::random_device rd; // non-deterministic generator
- static std::mt19937 gen(rd()); // to seed mersenne twister.
- static std::uniform_int_distribution<> dist(minimum, maximum); // distribute results between 1 and 6 inclusive.
- return (int)dist(gen);
- }
- int ChooseCooplexity(){
- int temp;
- std::cout << " Choose the difficult ( 3 = easy , 2 = medium , 1 = hard ) " << std::endl;
- std::cin >> temp;
- return temp;
- }
- int getNumberOfIterations(int r)
- {
- int NumberOfIteration = 0;
- int t;
- do
- {
- NumberOfIteration++;
- int f1 = minimum;
- t = (minimum + maximum) / 2.0;
- int f2 = t;
- if (f2< r) minimum = t;
- else maximum = t;
- } while (t!=r);
- return NumberOfIteration;
- }
- int getComplexity(int r)
- {
- int temp = ChooseCooplexity();
- int n = getNumberOfIterations(r);
- return n + 2 * temp;
- }
- void PlayGame()
- {
- std::cout << "Lets Start ! " << std::endl;
- getInterval();
- int rand = getRandomNumber();
- int value;
- int difficult = getComplexity(rand);
- for (int i = 0; i < difficult ; i++)
- {
- std::cout << " please, enter the number"<<std::endl;
- std::cin >> value;
- if (value > rand)
- {
- std::cout << " less"<< std::endl;
- }
- else if (value < rand)
- {
- std::cout << " more" << std::endl;
- }
- else {
- std::cout << "you find the number" << std::endl;
- break;
- }
- }
- }
- int main()
- {
- while (doesUserWantsToPlay()) {
- PlayGame();
- }
- system("pause");
- }
Add Comment
Please, Sign In to add comment