Help Needed with Lab Assignment in Coral

0
10
Asked By CodeWiz123 On

Hey everyone, I'm struggling with my lab assignment for class. The task is to write a program that reads 10 integers and outputs them in reverse order. For example, if the input is "2 4 6 8 10 12 14 16 18 20", the expected output should be "20 18 16 14 12 10 8 6 4 2". Each number must be followed by a space, even the last one, and then end with a newline.

Here's the code I've written so far:

integer array(10) userInts
integer i
integer x

for i = 0; i < userInts.size; i = i + 1:
userInts[i] = Get next input

x = Get next input

for i = 0; i < userInts.size; i = i + 1:
if x > userInts[i]:
Put userInts[i] to output
Put " to output
Put "n to output

However, I'm getting an error saying there's an unrecognized token near line 5. I'm not sure what to do next. Any advice would be greatly appreciated!

3 Answers

Answered By TechGuru88 On

It looks like the error is because of the colon at the end of your for and if statements. Remove the colons. The corrected lines should look like this:

for i = 0; i < userInts.size; i = i + 1
userInts[i] = Get next input

Answered By DebugMaster42 On

I noticed the variable 'x' seems unnecessary in this context. Your second loop also doesn't actually reverse the array. Focus on just flipping the output order in the second loop.

Answered By CodyCoder2 On

Glad to hear you figured it out! Just a tip: avoid using colons in those statements; they can definitely trip you up. Keep at it!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.