I'm really worried because I need this done until Monday.
This is the task:
Create a program with function main() and menu with functions for:
A ) Inserting several numbers from the keyboard into one-dimensional array (the numbers should be 5);
B ) Overwriting of the 1st array into second array in which the elements are put in reverse order.
C ) Overwriting of the second array into third array in which the elements are put in descending order.
D)Displaying information about the array. (I guess this is A,B and C)
The problem is that when I type the numbers I get some random number for an array...The other problem is that after I've written the numbers I also can't get back to 2,3, or 4...What should I add to my existing code?
Firstly, if you want an array that holds five numbers, you must declare it like this: int array[4]; not with [5], because that way you create an array that holds 6 numbers. Also try to hold the cases of the switch loop in brackets.
At line 33, you have the variable i unitialized, because you are inside a new case of the switch loop. Fix these things and see how it works
mutexe correct me if i am wrong, but doesnt every array start at position 0, so if i want five elements, i would have 0, 1, 2, 3, 4, as positions. So there would be stored five elements at these positions?
mutexe correct me if i am wrong, but doesnt every array start at position 0, so if i want five elements, i would have 0, 1, 2, 3, 4, as positions. So there would be stored five elements at these positions?
That's correct, however, mutexe was responding to your post which is incorrect:
Firstly, if you want an array that holds five numbers, you must declare it like this: int array[4]; not with [5],
There is a difference between declaring an array and referencing an array. When you declare an array, your specifiy the number of elements you want the array to hold, so if you want it to hold five elements, you declare it as int array[5];
When referencing the elements, you reference the five elements as [0] through [4].
Declaring int array[4]; would only generate storage for 4 elements.