-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModulized average calculator.txt
90 lines (67 loc) · 1.9 KB
/
Modulized average calculator.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
Question 2: modulize the solutions of either of the 2 definite loops and the indefinite loops
part 1E
start
//Open the program
output "Welcome to the Program"
//Prompt the user to enter values
getUserInput()
output "The average of the class is:"
output average
stop
getUserInput()
//Declarations of variables
num STUDENT_SCORES[] = new num[3]
num index = 0
num SIZE = 3
num total = 0
num DIVISOR = 3
num average = 0
while (index < SIZE) then
output "Please enter the student's score:"
input STUDENT_SCORES[index]
//Calculate the total of all scores
total = STUDENT_SCORES[index] + total
index = index + 1
endwhile
//Calculate the average
set average = total / DIVISOR
return
part 1F
start
//Declarations of variables
string userFirstChoice
//Prompt user to start the program or not
output "Welcome to the Program"
output "Do you wish to start the program, type YES or NO if: "
input userFirstChoice
//Prompt the user to enter values
calculateUserInput()
stop
calculateUserInput()
//Declarations of variables
num STUDENT_SCORES[] = new num[3]
num SIZE = 3
num total = 0
num DIVISOR = 3
num average = 0
string userChoice
while (userChoice == "YES") then
for index = 0 to (SIZE - 1) step 1
output "Please enter the student's score:"
input STUDENT_SCORES[index], index++
//Calculate the total of all scores
total = STUDENT_SCORES[index] + total
endfor
//calculate the average
set average = total / DIVISOR
output "The average of the class is:"
output average
//Reprompt user to choose to continue
output "Do you wish to continue entering another set of score, type YES or NO:"
input userChoice
endwhile
//Display a exit message
if (userChoice == "NO") then
output "Thank you for your answer, Goodbye."
endif
return