137k views
5 votes
Complete the PrintSelectedValues function to iterate over each element in dataValues. In each iteration, if the element is greater than 12, the program puts the element to output, and then puts "_" to output.

Ex: If dataValues's elements are 2 5 17 15, then output is:



17_15_



Here's the code presented:



Function PrintSelectedValues(integer array(?) dataValues) returns nothing

integer i



// Your solution goes here. Modify as needed

i = 0



Function Main() returns nothing

integer array(4) userNums

integer i



for i = 0; i < userNums.size; i = i + 1

userNums[i] = Get next input



PrintSelectedValues(userNums)

Complete the PrintSelectedValues function to iterate over each element in dataValues-example-1

1 Answer

4 votes

Final answer:

To complete the PrintSelectedValues function, use a for loop to iterate over each element in the dataValues array. If an element is greater than 12, add it to the output along with an underscore. Finally, display the output.

Step-by-step explanation:

The given code has a function called PrintSelectedValues that takes an integer array dataValues as input.

To iterate over each element in dataValues, we can use a for loop with a counter variable i. In each iteration, we check if the current element is greater than 12.

If it is, we add the element to the output and then add underscore '_' to the output. Finally, we display the output.

Here's the modified solution:

Function PrintSelectedValues(integer array(?) dataValues) returns nothing
integer i
for i = 0; i < dataValues.size; i = i + 1
if dataValues[i] > 12
output = output + dataValues[i]
output = output + "_"
endif
endfor

print(output)

User Ertes
by
7.4k points