-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearching through array and calculate.txt
68 lines (52 loc) · 1.57 KB
/
Searching through array and calculate.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
Question 3:Create a program and ask user for input
store the values in an array
search through the array
calculate the total of the stored values
start
//Declarations of variables
num count = 0
num USER_VALUES[] = new int[3]
num SIZE = 3
string userChoice
string answer
num storedValues = 0
num total = 0
num valueSearch
//Open the program
output "Welcome to the number search program"
//Prompt the user for values
while (count < 3)
output "Please enter your value: "
input USER_VALUES[count]
count + 1
endwhile
//Prompt the user to choose if they want to search
output "Do you wish to search for a value: "
input userChoice
//Set the search or close the program
if (userChoice <> "NO")
for index = 0 to (SIZE - 1) step 1
//Set the default variable to the array
valueSearch = USER_VALUES[index]
output "Is this the number you are looking for? "
output USER_VALUES[index] , index + 1
//Prompt the user to enter a answer
output "Type STOP or NO:"
input answer
//Calculate or iterate another element
if (answer <> "STOP")
index + 1
else
for counter = 0 to (SIZE - 1) step 1
//Calculate the total of the array
storedValues = USER_VALUES[counter] + storedValues
counter + 1
endfor
//Calculate the actual total without the searched value
total = storedValues - valueSearch
output "The total of the remaining values stored are: " , total
return
endif
endfor
endif
stop