-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestion 15 submit .txt
75 lines (56 loc) · 2.01 KB
/
question 15 submit .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
group members: Jet,Belinda,Sechaba Van Der Merwe
start
//Declarations of variables
num userNumber []
num finalaverage
num SIZE = 6
num valuesDistance
string choice
//Set an array to hold values
set userNumbers = new num[SIZE]
//Start the program by asking user if they want to create a set of numbers
output "Welcome to the Arithemtic set Program"
output "Do you wish to enter a set of 6 numbers: YES or NO"
input choice
//Check the user's choice
while (choice == "YES")
//Prompt user to enter values for the array
for index = 0 to SIZE - 1 step 1
output "Please enter your number:"
set userNumbers = userNumbers[index]
input userNumbers
endfor
//Call a method to calculate the average of the values
set finalAverage = CalulateArithmaticAverage (userNumbers)
//Display the values and show how far it is from the Average
DisplayValues(finalAverage,userNumbers)
//Reprompt user to enter another set or close program
output "Do you wish to enter another set of 6 numbers: YES or NO"
input choice
endwhile
//Display an exit message
if (choice == "NO")
output "Thank you for your answer. Goodbye."
endif
stop
//Create a method to calculate the average
num CalulateArithmaticAverage (num average)
//Declarations of variables
num total = 0
num SIZE = 6
//Calculate total of input and average
for i = 0 to SIZE - 1 step 1
//total will be all the userNumbers added together to the total
total += userNumbers[i]
endfor
average = total / SIZE
return average
//Create a method to display how far the values are to the average
void DisplayValues (num finalAverage, num userNumbers[])
//Declarations
num valuesDistance
//Display the distance of the values to the average
for counter = 0 to SIZE - 1 step 1
set valuesDistance = finalAverage - userNumber[counter]
output userNumber[counter] + " is " + valuesDistance " units away from the Average of your set numbers."
endfor