Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <stdlib.h>
- #include <time.h>
- #include <stdio.h>
- #include <iostream>
- #include <string>
- #include <conio.h>
- using namespace std;
- void convert(string *x, string *y) {
- int choice = 0;
- int random = 0;
- int num = 0;
- int ost = 0;
- int i = 0;
- string answer;
- srand(time(NULL));
- random = rand() % 200 + 1;
- num = random;
- *y = "";
- *x = "";
- i = 0;
- while (num / 2 != 0) {
- ost = num % 2;
- num = num / 2;
- if (ost == 1) y->insert(0, "1");
- if (ost == 0) y->insert(0, "0");// rezult in 2
- i++;
- }
- if (num == 1) y->insert(0, "1");
- i = 0;
- num = random;
- while (num / 16 != 0) {
- ost = num % 16;
- if (ost == 0) x->insert(0, "0");
- if (ost == 1) x->insert(0, "1");
- if (ost == 2) x->insert(0, "2");
- if (ost == 3) x->insert(0, "3");
- if (ost == 4) x->insert(0, "4");
- if (ost == 5) x->insert(0, "5");
- if (ost == 6) x->insert(0, "6");
- if (ost == 7) x->insert(0, "7");
- if (ost == 8) x->insert(0, "8");
- if (ost == 9) x->insert(0, "9");
- if (ost == 10) x->insert(0, "A");
- if (ost == 11) x->insert(0, "B");
- if (ost == 12) x->insert(0, "C");
- if (ost == 13) x->insert(0, "D");
- if (ost == 14) x->insert(0, "E");
- if (ost == 15) x->insert(0, "F");
- num = num / 16;
- }
- if (num != 0) x->insert(0, to_string(num));
- }
- int main()
- {
- int choice = 0;
- int random = 0;
- int num = 0;
- int ost = 0;
- string *rez;
- bool flag = true;
- int i = 0;
- string answer;
- string *hex;
- hex = new string;
- rez = new string;
- while (flag) {
- cout << "Converting testing\n\n";
- 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";
- cout << "Your choice: ";
- cin >> choice;
- switch (choice) {
- case 1: {
- while (answer != "STOP") {
- convert(hex, rez);
- cout << "Convert " << *rez << " from binary to hex\n";
- cout << "Your answer: ";
- cin >> answer;
- if (answer == *hex) {
- cout << "Correct\n";
- }
- if ((answer != *hex)&(answer != "STOP")) {
- cout << "Wrong, answer is " << *hex << endl;
- }
- }
- break;
- }
- case 2: {
- while (answer != "STOP") {
- convert(hex, rez);
- cout << "Convert " << *hex << " from hex to binary\n";
- cout << "Your answer: ";
- cin >> answer;
- if (answer == *rez) {
- cout << "Correct\n";
- }
- if ((answer != *rez)&(answer != "STOP")) {
- cout << "Wrong, answer is " << *rez << endl;
- }
- }
- break;
- }
- case 3: {
- flag = false;
- break;
- }
- }
- answer = " ";
- }
- return 0;
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement