Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- string comparer (int guess, int win, int d);
- // Main.#####################################################################################################################################
- int main () {
- int dif, d, win, guess=0, i; string cmp;
- srand ((unsigned) time (0));
- cout << "Dificulty (No. of digits): "; cin >> dif;
- if (dif/dif == 1) {
- d = pow (10, dif);
- win = rand () % d;
- while (guess != win){
- cout << dif << "-digit Code: "; cin >> guess;
- cmp = comparer (guess, win, d);
- if (guess == win){ cout << endl << "Victory!" << endl;}
- else if (guess > win){ cout << "Strenght: " << cmp << " (-)" << endl;}
- else if (guess < win){ cout << "Strenght: " << cmp << " (+)" << endl;}
- i = i + 1;
- cout << endl;}
- cout<< i << " Tr"; if (i==1){cout<< "y";}else{cout<< "ies";} cout<< " with " << dif << " digit"; if (dif!=1){cout<< "s";} cout<< ".";
- }else{cout << "Not a number.";}
- }
- // Comparer.#############################################################################################################################
- string comparer (int guess, int win, int d){
- string r;
- int num;
- num = abs (win - guess);
- if (num <= 1 ){r = "MAX" ;}
- else if (num <= (d * 0.005)) {r = "9" ;}
- else if (num <= (d * 0.01 )) {r = "8" ;}
- else if (num <= (d * 0.05 )) {r = "7" ;}
- else if (num <= (d * 0.10 )) {r = "6" ;}
- else if (num <= (d * 0.15 )) {r = "5" ;}
- else if (num <= (d * 0.20 )) {r = "4" ;}
- else if (num <= (d * 0.30 )) {r = "3" ;}
- else if (num <= (d * 0.40 )) {r = "2" ;}
- else if (num <= (d * 0.50 )) {r = "1" ;}
- else {r = "0" ;}
- return (r);}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement