Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <cstdio>
  5. #include <random>
  6. #include <set>
  7. // These three "#include" statements are for the rand() code.
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <time.h>
  11. using namespace std;
  12.  
  13. int userScore = 0;
  14. int random1To20();
  15. int random1To20()
  16. {
  17.     int targetNumber1;
  18.     int least = 1;
  19.     int most = 20;
  20.     targetNumber1 = rand() % most + least;
  21.     return targetNumber1;
  22. }
  23.  
  24. int indicateAnswer();
  25.  
  26. int pointRound();
  27. void text()
  28. {
  29.     int respnse;
  30.     cout << "Your score is " << userScore << endl;
  31.  
  32.     cout << "Decide whether " << random1To20 << " is one of the multiples or is not a muliple at all " << endl;
  33.  
  34.     cout << "a. The number is a multiple of 2. " << endl;
  35.  
  36.     cout << "b. The number is a multiple of 3. " << endl;
  37.  
  38.     cout << "c. The number is a multiple of both 2 and 3. " << endl;
  39.  
  40.     cout << "d. None of these are true. " << endl;
  41.     char response;
  42.     cin >> response;
  43.     return response;
  44. }
  45.  
  46. char totalUpRightAnswers(int points)
  47. {
  48.     if (points % 2 == 0 && points % 3 == 0)
  49.     {
  50.         return 'c';
  51.     }
  52.     else if (points % 2 == 0)
  53.     {
  54.         return 'a';
  55.     }
  56.     else if (points % 3 == 0)
  57.     {
  58.         return 'b';
  59.     }
  60.     else
  61.     {
  62.         return 'd';
  63.     }
  64. }
  65.  
  66.  
  67. bool processUserGuess(int points, char userAnswer)
  68. {
  69.     char correctness = totalUpRightAnswers(points);
  70.     return (userAnswer == correctness);
  71. }
  72.  
  73. int pointRound()
  74. {
  75.     int points = random1To20();
  76.     char answer = indicateAnswer(points);
  77.     bool correctness = processUserGuess(points, answer);
  78.     // This if statement is for make scoring for the correct answer.
  79.     if (correctness)
  80.     {
  81.         cout << "You are right!";
  82.         return 1;
  83.     }
  84.     else
  85.     {
  86.         cout << "Oh no, you are wrong.";
  87.         return -1;
  88.     }
  89. }
  90.  
  91. int main()
  92. {
  93.     userScore = 0;
  94.     const int highestScore = 10;
  95.     srand(time(NULL));
  96.  
  97.     do{
  98.         cout << "Your scroe is " << userScore << endl;
  99.         userScore += pointRound();
  100.     } while (userScore < (highestScore)
  101.  
  102.     return 0;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement