wuiyang

pseudocode example

Aug 14th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. http://i.imgur.com/XVfrg0k.png
  2. main:
  3. START
  4.     userType = printMainMenu()
  5.     IF userType == 1 THEN
  6.         DO
  7.             operationsType = printOptionMenu()
  8.             IF operationsType != 4 THEN
  9.                 levelType = printLevelMenu()
  10.                 IF levelType != 4 THEN
  11.                     DO
  12.                         correctQuestion = 0
  13.                         i = 0
  14.                         WHILE i < 10
  15.                             correctQuestion += printQuestion(operationsType, levelType)
  16.                             i++
  17.                         END WHILE
  18.                         DISPLAY "You did " & correctQuestion & " out of 10 questions"
  19.                         IF correctQuestion >= 8 && levelType <=3 THEN
  20.                             continueOrExit = finishedQuestionCongrats()
  21.                             IF continueOrExit == 1 THEN
  22.                                 levelType++
  23.                             ELSE
  24.                                 continueOrExit--
  25.                             END IF
  26.                         ELSE
  27.                             continueOrExit = finishedQuestion()
  28.                         END IF
  29.                         IF continueOrExit == 2 THEN
  30.                             levelType = 4
  31.                         END IF
  32.                     WHILE continueOrExit == 1
  33.                 END IF
  34.             END IF
  35.         WHILE levelType == 4 && operationsType != 4
  36.     END IF
  37. END
  38.  
  39. http://i.imgur.com/ssA5laG.png
  40. printQuestion:
  41. START (operationsType, levelType)
  42.     IF levelType == 1 THEN
  43.         range = 11
  44.     ELSE IF levelType == 2 THEN
  45.         range = 101
  46.     ELSE IF levelType == 3 THEN
  47.         range = 1001
  48.     END IF
  49.     num1 = rand() % range
  50.     num2 = rand() % range
  51.     IF operationsType == 1 THEN
  52.         answer = num1 + num2
  53.         DISPLAY num1 & " + " & num2 & " = "
  54.     ELSE IF operationsType == 2 THEN
  55.         answer = num1 - num2
  56.         DISPLAY num1 & " - " & num2 & " = "
  57.     ELSE IF operationsType == 3 THEN
  58.         answer = num1 * num2
  59.         DISPLAY num1 & " * " & num2 & " = "
  60.     END IF
  61.     GET userAns
  62.     IF userAns == answer THEN
  63.         DISPLAY "You answer is correct"
  64.         result = 1
  65.     ELSE
  66.         DISPLAY "Your answer is incorrect, " & answer & " is the correct answer"
  67.         result = 0
  68.     END IF
  69.     RETURN result
  70. END
  71.  
  72. http://i.imgur.com/klSapQB.png
  73. printMainMenu:
  74. START
  75.     DISPLAY "Welcome to math quiz"
  76.     DISPLAY "(1) Start the math quiz"
  77.     DISPLAY "(2) Exit the math quiz"
  78.     userInput = getUserInput(1,2)
  79.     RETURN userInput
  80. END
  81.  
  82. printOptionMenu:
  83. START
  84.     DISPLAY "Please choose a arthimetic operations"
  85.     DISPLAY "(1) +"
  86.     DISPLAY "(2) -"
  87.     DISPLAY "(3) *"
  88.     DISPLAY "(4) Exit"
  89.     userInput = getUserInput(1,4)
  90.     RETURN userInput
  91. END
  92.  
  93. printLevelMenu:
  94. START
  95.     DISPLAY "Please choose a level"
  96.     DISPLAY "(1) Beginner"
  97.     DISPLAY "(2) Intermediate"
  98.     DISPLAY "(3) Advanced"
  99.     DISPLAY "(4) Back to arthimetic options"
  100.     userInput = getUserInput(1,4)
  101.     RETURN userInput
  102. END
  103.  
  104. finishedQuestion:
  105. START
  106.     DISPLAY "Choose an option"
  107.     DISPLAY "(1) Continue"
  108.     DISPLAY "(2) Exit to menu"
  109.     userInput = getUserInput(1,2)
  110.     RETURN userInput
  111. END
  112.  
  113. finishedQuestionCongrats:
  114. START
  115.     DISPLAY "You're such a genius, congratulations you have owned all the questions"
  116.     DISPLAY "Choose an option"
  117.     DISPLAY "(1) To next level"
  118.     DISPLAY "(2) Continue with same level"
  119.     DISPLAY "(3) Exit to menu"
  120.     userInput = getUserInput(1,3)
  121.     RETURN userInput
  122. END
  123.  
  124. getUserInput:
  125. START
  126.     DO
  127.         DISPLAY "Select an option"
  128.         GET userType
  129.         IF userType < min || userType > max THEN
  130.             DISPLAY "Error! Invalid option!"
  131.         END IF
  132.     WHILE userType < min || userType > max
  133.     RETURN userType
  134. END
Advertisement
Add Comment
Please, Sign In to add comment