Write a program that uses the following functions:
Fill_array() takes as arguments the name of an array of double values and an array
size. It prompts the user to enter double values to be entered in the array. It ceases taking
input when the array is full or when the user enters non-numeric input, and it
returns the actual number of entries.
Show_array() takes as arguments the name of an array of double values and an array
size and displays the contents of the array.
Reverse_array() takes as arguments the name of an array of double values and an
array size and reverses the order of the values stored in the array.
The program should use these functions to fill an array, show the array, reverse the array,
show the array, reverse all but the first and last elements of the array, and then show the
array.
My question is where do I go from here? I figure I have to re-reverse the array to retrieve the original array, but how would I go about reversing all the integers in the original array except for the first and the last ones?If anyone could drop a hint or something that would be great.
P.s. is there a value i could return from Reverse_array() other than temp? could I just put 1 and it would have no effect on the function of the program? Or would it be best to just declare the function as type void since no return value is actually needed? If "void" would be the best options, does this conserve space the most since the compiler has one less step to do?
If it makes no sense for a function to return a value, then it shouldn't return a value.
Also, you didn't catch that value.
Reverse_array(firstarray + 1, num_entered +1); ¿why the array increased its size?
Actually the second parameter it is not the size, but how many elements do you want to work with. Considerer it as passing a range, like in void reverse ( Iterator first, Iterator last); // [)
By the way
1 2
cin >> size;
double firstarray[size];
is against the standard. If you don't know the size, use std::vector
"Reverse array takes a double array and array size as arguments."
num_entered + 1 means that your array is one element bigger than itself. That's like saying that I'm shorter than myself doesn't make sense does it?
what you should need is num_entered - 2, you take one element from array size because you are starting the count one element past the beggining and another one because you don't want to include the last one.
EDIT: The mumbo jumbo is there because you are reading past the memory that was allocated for your array.