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
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
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.
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
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically