Guest User

Untitled

a guest
Jul 22nd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int MathQ();
  7. int GeoQ();
  8.  
  9. int main()
  10. {
  11. //identifier declaration
  12. int score1 = 0, score2 = 0, highM = 0, highG = 0;
  13. int option = 0;
  14.  
  15. cout << "Would you like to play either the 1.Math Quiz or 2.Geography Quiz: ";
  16. cin>>option;
  17.  
  18. if (option==1)
  19. {
  20. //call function
  21. score1 = MathQ();
  22. }
  23. else if (option==2)
  24. {
  25. //call function
  26. score2 = GeoQ();
  27. }
  28. else
  29. cout << "unknown";
  30.  
  31. if(option==1)
  32. highM=score1;
  33. else if(option==2)
  34. highG=score2;
  35. //display score
  36. cout <<"Math Score: " <<highM <<endl;
  37. cout <<"Geography Score: " <<highG <<endl;
  38. return 0;
  39. }
  40.  
  41. //---Fuction Definition
  42.  
  43. int MathQ()
  44. {
  45. int ans, count = 0, score = 0;
  46.  
  47. cout <<"2 + 2 = ";
  48. cin>>ans;
  49. if (ans == 4)
  50. {
  51. score+=10;
  52. count++;
  53. }
  54.  
  55. cout <<"3 x 3 = ";
  56. cin>>ans;
  57. if (ans == 9)
  58. {
  59. score+=10;
  60. count++;
  61. }
  62.  
  63. cout <<"10 / 2 = ";
  64. cin>>ans;
  65. if (ans == 5)
  66. {
  67. score+=10;
  68. count++;
  69. }
  70.  
  71. cout << "Your Score is: " <<score <<endl;
  72. cout << "You have answered " <<count <<"questions correct." <<endl;
  73.  
  74. return score;
  75.  
  76. }
  77.  
  78. int GeoQ()
  79. {
  80. int count = 0, score = 0;
  81. string ans;
  82.  
  83. cout <<"What is the Capital of Pakistan?";
  84. cin>>ans;
  85. if (ans == "Islamabad")
  86. {
  87. score+=10;
  88. count++;
  89. }
  90.  
  91. cout <<"What is the Capital of Florida?";
  92. cin>>ans;
  93. if (ans == "Tallahassee")
  94. {
  95. score+=10;
  96. count++;
  97. }
  98.  
  99. cout <<"What is the Capital of Malaysia?";
  100. cin>>ans;
  101. if (ans == "Kuala Lumpur")
  102. {
  103. score+=10;
  104. count++;
  105. }
  106.  
  107. cout << "Your Score is: " <<score <<endl;
  108. cout << "You have answered " <<count <<"questions correct." <<endl;
  109.  
  110. return score;
  111.  
  112. }
Add Comment
Please, Sign In to add comment