Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. string comparer (int guess, int win, int d);
  5.  
  6.  
  7. // Main.#####################################################################################################################################
  8. int main () {
  9. int dif, d, win, guess=0, i; string cmp;
  10. srand ((unsigned) time (0));
  11. cout << "Dificulty (No. of digits): "; cin >> dif;
  12. if (dif/dif == 1) {
  13. d = pow (10, dif);
  14. win = rand () % d;
  15. while (guess != win){
  16. cout << dif << "-digit Code: "; cin >> guess;
  17. cmp = comparer (guess, win, d);
  18. if (guess == win){ cout << endl << "Victory!" << endl;}
  19. else if (guess > win){ cout << "Strenght: " << cmp << " (-)" << endl;}
  20. else if (guess < win){ cout << "Strenght: " << cmp << " (+)" << endl;}
  21. i = i + 1;
  22. cout << endl;}
  23. cout<< i << " Tr"; if (i==1){cout<< "y";}else{cout<< "ies";} cout<< " with " << dif << " digit"; if (dif!=1){cout<< "s";} cout<< ".";
  24. }else{cout << "Not a number.";}
  25. }
  26.  
  27.  
  28. // Comparer.#############################################################################################################################
  29. string comparer (int guess, int win, int d){
  30. string r;
  31. int num;
  32. num = abs (win - guess);
  33. if (num <= 1 ){r = "MAX" ;}
  34. else if (num <= (d * 0.005)) {r = "9" ;}
  35. else if (num <= (d * 0.01 )) {r = "8" ;}
  36. else if (num <= (d * 0.05 )) {r = "7" ;}
  37. else if (num <= (d * 0.10 )) {r = "6" ;}
  38. else if (num <= (d * 0.15 )) {r = "5" ;}
  39. else if (num <= (d * 0.20 )) {r = "4" ;}
  40. else if (num <= (d * 0.30 )) {r = "3" ;}
  41. else if (num <= (d * 0.40 )) {r = "2" ;}
  42. else if (num <= (d * 0.50 )) {r = "1" ;}
  43. else {r = "0" ;}
  44. return (r);}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement