TheRasVa

Задача 2,16

Mar 21st, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <time.h>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     setlocale(LC_ALL, "russian");
  9.     system("color 0A");
  10.     srand(time(NULL));
  11.     int i=0, guess, answer, wrongnum=0;
  12.     double score, rightnum = 0, n;
  13.     cout << "Введите кол-во примеров: ";
  14.     cin >> n;
  15.     while (i < n)
  16.     {
  17.         i++;
  18.         int a = rand() % 100;
  19.         int b = rand() % 100;
  20.         if (a < 25)
  21.         {
  22.             cout << a << '+' << b << "= ";
  23.             guess = a + b;
  24.         }
  25.         if (a > 25 && a < 50)
  26.         {
  27.             cout << a << '-' << b << "= ";
  28.             guess = a - b;
  29.         }
  30.         if (a > 50 && a < 75)
  31.         {
  32.             cout << a << '*' << b << "= ";
  33.             guess = a * b;
  34.         }
  35.         if (a > 75)
  36.         {
  37.             cout << a << '/' << b << "= (усекая) ";
  38.             guess = a / b;
  39.         }
  40.         cin >> answer;
  41.         if (guess == answer)
  42.         {
  43.             rightnum++;
  44.             cout << "Верно, счет: правильно: " << rightnum << " \\ " << n << " неправильно: " << wrongnum << " \\ " << n <<endl;
  45.         }
  46.         else
  47.         {
  48.             wrongnum++;
  49.             cout << "Неверно, счет: правильно: " << rightnum << " \\ " << n << " неправильно: " << wrongnum << " \\ " << n <<endl;
  50.         }
  51.     }
  52.     score = rightnum / n * 100;
  53.     if (rightnum>wrongnum)
  54.     {
  55.         cout << "Вы выграли! Ваш счет - " << score << "% правильных." << endl;
  56.     }
  57.     else
  58.     {
  59.         cout << "Вы проиграли! Ваш счет - " << score << "% правильных." << endl;
  60.     }
  61.     system("pause");
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment