Advertisement
555oya

Untitled

Jun 3rd, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.64 KB | None | 0 0
  1.  
  2. #include "pch.h"
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include <stdio.h>
  6. #include <iostream>
  7. #include <string>
  8. #include <conio.h>
  9. using namespace std;
  10.  
  11. void convert(string *x, string *y) {
  12.  
  13.     int choice = 0;
  14.     int random = 0;
  15.     int num = 0;
  16.     int ost = 0;
  17.     int i = 0;
  18.     string answer;
  19.    
  20.  
  21.     srand(time(NULL));
  22.     random = rand() % 200 + 1;
  23.     num = random;
  24.     *y = "";
  25.     *x = "";
  26.     i = 0;
  27.     while (num / 2 != 0) {
  28.         ost = num % 2;
  29.         num = num / 2;
  30.         if (ost == 1) y->insert(0, "1");
  31.         if (ost == 0) y->insert(0, "0");// rezult in 2
  32.         i++;
  33.     }
  34.     if (num == 1) y->insert(0, "1");
  35.     i = 0;
  36.     num = random;
  37.     while (num / 16 != 0) {
  38.         ost = num % 16;
  39.         if (ost == 0) x->insert(0, "0");
  40.         if (ost == 1) x->insert(0, "1");
  41.         if (ost == 2) x->insert(0, "2");
  42.         if (ost == 3) x->insert(0, "3");
  43.         if (ost == 4) x->insert(0, "4");
  44.         if (ost == 5) x->insert(0, "5");
  45.         if (ost == 6) x->insert(0, "6");
  46.         if (ost == 7) x->insert(0, "7");
  47.         if (ost == 8) x->insert(0, "8");
  48.         if (ost == 9) x->insert(0, "9");
  49.         if (ost == 10) x->insert(0, "A");
  50.         if (ost == 11) x->insert(0, "B");
  51.         if (ost == 12) x->insert(0, "C");
  52.         if (ost == 13) x->insert(0, "D");
  53.         if (ost == 14) x->insert(0, "E");
  54.         if (ost == 15) x->insert(0, "F");
  55.         num = num / 16;
  56.     }
  57.     if (num != 0) x->insert(0, to_string(num));
  58.    
  59. }
  60.  
  61. int main()
  62. {
  63.     int choice = 0;
  64.     int random = 0;
  65.     int num = 0;
  66.     int ost = 0;
  67.     string *rez;
  68.     bool flag = true;
  69.     int i = 0;
  70.     string answer;
  71.     string *hex;
  72.  
  73.     hex = new string;
  74.     rez = new string;
  75.  
  76.    
  77.         while (flag) {
  78.             cout << "Converting testing\n\n";
  79.             cout << "If you want practice 2 -> 16 enter 1\nIf you want practice 16 -> 2 enter 2\nIf you want to exit enter 3\n";
  80.             cout << "Your choice: ";
  81.             cin >> choice;
  82.            
  83.             switch (choice) {
  84.                 case 1: {
  85.                     while (answer != "STOP") {
  86.                         convert(hex, rez);
  87.                         cout << "Convert " << *rez << " from binary to hex\n";
  88.                         cout << "Your answer: ";
  89.                         cin >> answer;
  90.                         if (answer == *hex) {
  91.                             cout << "Correct\n";
  92.                         }
  93.                         if ((answer != *hex)&(answer != "STOP")) {
  94.                             cout << "Wrong, answer is " << *hex << endl;
  95.  
  96.                         }
  97.                     }
  98.                     break;
  99.                 }
  100.                 case 2: {
  101.                     while (answer != "STOP") {
  102.                         convert(hex, rez);
  103.                         cout << "Convert " << *hex << " from hex to binary\n";
  104.                         cout << "Your answer: ";
  105.                         cin >> answer;
  106.                         if (answer == *rez) {
  107.                             cout << "Correct\n";
  108.                         }
  109.                         if ((answer != *rez)&(answer != "STOP")) {
  110.                             cout << "Wrong, answer is " << *rez << endl;
  111.                         }
  112.                     }
  113.                     break;
  114.                 }
  115.                 case 3: {
  116.                     flag = false;
  117.                     break;
  118.                 }
  119.             }
  120.             answer = " ";
  121.            
  122.         }
  123.    
  124.  
  125.         return 0;
  126.         _getch();
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement