C4Grey

Маринко :)

Jan 6th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. // Multiplier.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <time.h>
  7. #include <conio.h>
  8. #include <ctype.h>
  9. using namespace std;
  10.  
  11. int _tmain(int argc, _TCHAR* argv[])
  12. {  
  13.     int answer = -1;
  14.     //Switching the console to cyrillic
  15.     setlocale(LC_ALL, "Russian");
  16.     int first, second, mult;
  17.     //Setting random function seed based in time
  18.     srand(time(0));
  19.     first = rand() % 9 + 1;
  20.     second = rand() % 9 + 1;
  21.     mult = first * second;
  22.     cout << "Сколько будет " << first << " x " << second << " ?" << "\n";
  23.     cin >> answer;
  24.     //In case if user inputed some negative number or not-digit character(answer variable still be equel to -1)
  25.     if(answer < 0)
  26.         cout << "Ошибка: Ответ должен быть положительным числом";  
  27.     else
  28.     {
  29.         if(answer != mult)
  30.             cout << "Умри, неверный! " << first << " x " << second << " = " << mult;
  31.         else
  32.             cout << "Правильно!";
  33.     }
  34.     cout << "\n\nНажмите любую клавишу для выхода...";
  35.     //Suspending the console
  36.     _getch();
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment