Ask coding questions

← Back to all posts
Edhesive Assignment 5 help
jedifan65 (3)

So my code manages to run every sample run correctly except for sample run 4 which has it as a decreasing array instead of an unsorted array:
Sample Run 1
How long do you want the array?
Enter a number
Enter a number
Enter a number
Your array is {1.3, 1.5, 8.1}
The average is 3.633333333333333
The range is 6.8
The array is sorted in increasing order

Sample Run 2
How long do you want the array?
Not a valid length!

Sample Run 3
How long do you want the array?
Enter a number
Enter a number
Your array is {3.6, 0.8}
The average is 2.2
The range is 2.8
The array is sorted in decreasing order

Sample Run 4
How long do you want the array?
Enter a number
Enter a number
Enter a number
Enter a number
Enter a number
Your array is {2.0, 4.1, 6.4, 0.2, 1.3}
The average is 2.8
The range is 6.2
The array is unsorted

Here's my code:
Please help me. This assignment is due today.
EDIT: Please help

AllAwesome497 (367)

Instead of pasting the code here, link the repl to the post. Dong so not only makes it readable, but it also lets us see firsthand and easily fork+edit it, so that we can better help you.

jedifan65 (3)

@AllAwesome497 Sorry about that. I'm new to this website, so forgive me for not being clear about everything.

jeefma (8)

Also would be helpful to let us know the assignment as well since trying to piece your assignment together from the code kinda isn't fun

jedifan65 (3)

@jeefma Sorry about that. Here's the assignment details: Instructions
For this assignment, you will write a program which creates an array of decimal numbers from a user's input, then returns some simple statistics about the array.

The program should first ask the user how long they wish the array to be (must be a positive integer). If the user enters a non-positive integer then the program should display "Not a valid length!", then stop. Otherwise, the program should create an array of this length, then prompt the user to enter double values one at a time, filling the array from the start with the user's inputs until the array is full.

Once the array is filled the program should print the numbers in the array, followed by the average (arithmetic mean) of the values, the range of the values, and a statement on whether the array is sorted in increasing order, decreasing order or neither.

The average of the values is found by dividing the sum of the numbers by the amount of numbers in the array (note: this may cause roundoff errors, which you do not need to worry about for this assignment).
The range of the numbers is found by subtracting the smallest number in the array from the largest number in the array.
The array is sorted in increasing order if every number is greater than or equal to the previous number. The array is sorted in decreasing order if every element is less than or equal to the previous number. If neither of these is true then the list is unsorted. If every element on the list is the same, then it is counted as being in increasing order.


did you ever figure it out? because i am stuck on this part as well :/