Facebook
From Wojtek legieta kl.1P, 3 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 142
  1. #include <iostream>
  2. #include <time.h>
  3. using namespace std;
  4. int main()
  5. {
  6. srand(time(NULL));
  7.  
  8.  bool strzal[100]={false};
  9.     int qmin=1,qmax=100;
  10.     int strzel;
  11.     int pr=1;
  12.     string pod;
  13.     cout << "Program zgaduje jaka liczbe masz w pamiei,jezeli liczba jest za duza to napisz d a jak za mala m gdy program zgadnie napisz +" << endl;
  14.     while(true)
  15.     {
  16.  
  17.         again:
  18.         strzel = rand()%(qmax-qmin+1)+qmin;
  19.         if (strzal[strzel-1]==true) goto again;
  20.         cout << strzel << endl;
  21.         if (qmin==qmax)
  22.         {
  23.             cout << "Liczba o ktorej pomyslales to: " << qmin << endl;
  24.             cout << "Udalo mi sie za  " << pr << endl;
  25.             break;
  26.         }
  27.         podaj:
  28.         cout << "-";
  29.         cin >> pod;
  30.         if (pod=="m")
  31.         {
  32.             qmin=strzel+1;
  33.         }
  34.         else if (pod=="d")
  35.         {
  36.             qmax=strzel-1;
  37.         }
  38.         else if (pod=="+")
  39.         {
  40.             cout << "Udalo mi sie za: "<<pr;
  41.             break;
  42.         }
  43.         else goto podaj;
  44.  
  45.         pr++;
  46.     }
  47. }
  48.