Guest User

My solutions to the Very Easy questions

a guest
Sep 16th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. Easy Questions
  2.  
  3. 1. int suit, number;
  4.  
  5. for (int i = 0; i < 2; i = i + 1)
  6. suit = rand()%4+1
  7. number = rand()%13+1
  8.  
  9. if (number == 1)
  10. cout << "You drew the Ace of";
  11. if (number == 11)
  12. cout << "You drew the Jack of";
  13. if (number == 12
  14. cout << "You drew the Queen of";
  15. if (number == 13)
  16. cout << "You drew the King of";
  17. if (number > 1 && number < 11)
  18. cout << "You drew the" << number << "of";
  19.  
  20. if (suit == 1)
  21. cout << " Spades";
  22. ##etc for other suits
  23.  
  24. 2. int time = 9999
  25.  
  26. int SS = time %60
  27. int MM = time /60
  28. time = time - SS
  29. int MM = time %60
  30. int HH = time/60
  31.  
  32. cout << HH << ":" << MM << ":" << SS
  33.  
  34. 3. int resultA, resultB, resultC;
  35. int coinA, coinB;
  36. for (int i = 0; i < 1001; i = i + 1)
  37. {coinA = rand()%2
  38. coinB = rand()%2
  39. if (coinA+coinB == 0)
  40. resultA = resultA + 1;
  41. if (coinA+coinB == 1)
  42. resultB = resultB + 1;
  43. if (coinA+coinB == 2)
  44. resultC = resultC + 1;}
  45.  
  46. float percentageA, percentageB, percentageC;
  47. percentageA = (resultA/1000)*100
  48. percentageB = (resultB/1000)*100
  49. percentageC = (resultC/1000)*100
  50.  
  51. cout << "The percentage of two heads was" << percentageA
  52. cout << "The percentage of two tails was" << percentageB
  53. cout << "The percentage of one head and one tail was" << percentageC
  54.  
  55. 4. int C[14]
  56.  
  57. for (int i = 0; i < 5; i = i +1)
  58. C[i] = A[i]
  59.  
  60. for (int i = 0; i < 10; i = i+1)
  61. C[i+5] = B[i]
  62.  
  63. 5. int money;
  64. float interest;
  65. int x; (years)
  66.  
  67. for (int i = 0; i < x; i = i + 1)
  68. money = money * (interest+1)
  69.  
  70. 6. int X[199];
  71. int tempstorage;
  72.  
  73. for (int i = 0; i < 200; i = i + 1)
  74. X[i] = rand()%11
  75.  
  76. for (int i = 0; i < 200; i = i + 1)
  77. for (int j = 0; j < 200; j = j + 1)
  78. if X[j] < X[i]
  79. {tempstorage = X[i];
  80. X[i] = X[j];
  81. X[j] = tempstorage;}
  82.  
  83. (same for the other list, just swap the <> direction)
  84.  
  85. I'm too lazy to do the mode one.
  86.  
  87. 7. int A, B, C;
  88. float C
  89. cin << A << B
  90.  
  91. while (A > 0)
  92. {if (A - B < 0)
  93. {D = A;
  94. break;}
  95. A = A - B
  96. C = C + 1
  97. }
  98.  
  99. cout << "The result of the division is" << C << "with a remainder of" << D
  100.  
  101. 8. int roman;
  102. cin << roman;
  103.  
  104. if roman == 10
  105. cout << "X"
  106.  
  107. if roman > 5
  108. {cout << "V";
  109. roman = roman - 5;
  110. if (roman == 4)
  111. cout << "IV"
  112. else
  113. while (roman > 0)
  114. {cout << "I";
  115. roman = roman - 1;}}
  116.  
  117. if roman == 5
  118. cout << "V"
  119.  
  120. if roman < 5
  121. {if roman == 4
  122. cout << "IV"
  123. else
  124. while (roman > 0)
  125. {cout << "I";
  126. roman = roman - 1;}}
  127.  
  128. 9. ##num1 and num2 are the two integers to be added, num5 is the final number, the rest are for code usage
  129.  
  130. int num1, num2, num3, num5;
  131. float num4;
  132. num4 = num1;
  133.  
  134. ##counting the number of digits by dividing by 10 until the number is a decimal
  135. while (num4 > 1)
  136. {num3 = num3 + 1;
  137. num4 = num4 /10;}
  138.  
  139. num5 = num1 + (num2 * pow(10,num3))
  140. cout << num5
  141.  
  142. 10. Don't know how to do this.
  143.  
  144. 11. I haven't the slightest clue how this maths.
  145.  
  146. 12. for (int i = 0; i < 1000; i = i + 1)
  147. for (int j = 0; j < 1000; j = j + 1)
  148. if ( i != j && X[i] == X[j])
  149. cout << "The repeated number was << cout << X[i];
  150.  
  151. follow me @realdonaldtrump or @mido9_2 (I have no tweets, this is just a watermark)
Add Comment
Please, Sign In to add comment