Help Needed with Lab Program for Reversing Integers

0
4
Asked By CodingNinja89 On

I'm having some trouble with my class lab where I need to write a program that takes a list of 10 integers and outputs them in reverse order. The output should include a space after each number, even the last one, followed by a newline. For example, if the input is 2 4 6 8 10 12 14 16 18 20, the output should be 20 18 16 14 12 10 8 6 4 2. To do this, I first read the integers into an array and then print them in reverse. Here's what my code looks like:

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

The lab says there's an unrecognized token near line 5, and I'm not sure how to fix it. Any advice would be greatly appreciated! (I'm using Coral for coding.)

3 Answers

Answered By DebugMaster99 On

I checked your code and that colon at the end of line 5 shouldn't be there. It can definitely cause issues. Good catch!

Answered By CodeWhisperer22 On

Also, I'm not exactly sure what the variable `x` is doing in your code. It doesn't seem to contribute to reversing the output. After fixing the colon issue, you should focus on how you’re going to reverse the integer array.

Answered By TechieGuru42 On

It looks like the issue lies in your `for` and `if` statements. The colon at the end of line 5 is causing the error. Try this:

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

Removing the colons should help clear the error.

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.