Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <string>
  4. using namespace std;
  5. struct myData
  6. {
  7.     string m1;
  8.     string m2;
  9.     string m3;
  10.     string m4;
  11.     string m5;
  12.     string m6;
  13.  
  14.     int* a;
  15.     int* b;
  16.     bool povtor;
  17.     int sovpadeniya = 0;
  18. };
  19.  
  20. void initStrings(myData* strings)
  21. {
  22.     strings->m1 = "Введите 6 чисел от 1 до 36, после каждого числа нажмите Enter";
  23.     strings->m2 = "Неправильный ввод";
  24.     strings->m3 = "Уже есть такое число, введите другое";
  25.     strings->m4 = "Начало розыграша";
  26.     strings->m5 = "Совпадение! :";
  27.     strings->m6 = "Всего совпало:";
  28. }
  29. void inputData( myData*strings)
  30. {
  31.     strings->a = (int*)malloc(sizeof(int) * 6);
  32.     strings->b = (int*)malloc(sizeof(int) * 6);
  33.  
  34.     //int* ap = a;
  35.     //int* bp = &b[0];
  36.  
  37.     cout << strings->m1 << endl;
  38.  
  39.     string input;
  40.     for (int x = 0; x < 6; x++)
  41.     {
  42.         cin >> input;
  43.         strings->a[x] = stoi(input);
  44.  
  45.         if (strings->a[x] < 1 || strings->a[x]>36)
  46.         {
  47.             cout << strings->m2 << endl;
  48.             x--;
  49.         }
  50.  
  51.         for (int y = 0; y < x; y++)
  52.             if (strings->a[x] == strings->a[y])
  53.             {
  54.                 cout << strings->m3 << endl;
  55.                 x--;
  56.             }
  57.     }
  58. }
  59.  
  60. void lotteryStart(myData* strings)
  61. {
  62.     cout << strings->m4 << endl;
  63.  
  64.     for (int x = 0; x < 6; x++)
  65.     {
  66.         int j = rand() % 37;
  67.  
  68.         strings->povtor = true;
  69.         strings->b[x] = rand() % 36 + 1;
  70.  
  71.         cout << endl;
  72.  
  73.         for (int y = 0; y < x; y++)
  74.             if (strings->b[x] == strings->b[y])
  75.             {
  76.                 x--;
  77.                 strings->povtor = false;
  78.             }
  79.  
  80.         if (strings->povtor)
  81.         {
  82.             for (int y = 0; y < 6; y++)
  83.                 if (strings->a[y] == strings->b[x])
  84.                 {
  85.                     cout << strings->m5 << endl;
  86.                     strings->sovpadeniya++;
  87.                 }
  88.             cout << strings->b[x] << endl;
  89.         }
  90.     }
  91. }
  92.  
  93. void lotteryResults(myData* strings)
  94. {
  95.     cout << strings->m6 << strings->sovpadeniya << endl;
  96. }
  97.  
  98. int main()
  99. {
  100.     setlocale(LC_ALL, "Russian");
  101.     struct myData*Str = (myData*)malloc(sizeof(myData));
  102.  
  103.     cout << endl;
  104.  
  105.     srand(time(0));
  106.  
  107.     initStrings(Str);
  108.     inputData(Str);
  109.     lotteryStart(Str);
  110.     lotteryResults(Str);
  111.  
  112.     system("pause");
  113.     return 0;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement