#include <iostream>
#include <stdlib.h>
usingnamespace std;
constint MAX_INTEGERS = 20; //Max numbers in array always constant
void fill_array(int a[], int size, int& number);
int main()
{
if (system("CLS")) system("clear"); //clears garbage from screen
int integers[MAX_INTEGERS], number;
cout << "This program outputs an array backwards" << endl;
fill_array(integers, MAX_INTEGERS, number);
return 0;
}
void fill_array(int a[], int size, int& number)
{
cout << "Enter up to " << size << " integers.\n"
<< "Mark the end of the list with a 0.\n";
int next, index = 0;
cin >> next;
while ((next >= 1) && (index < size)) //prompts user for integers until 0 is input
{
a[index] = next;
index++;
cin >> next;
}
number = index;
cout << "The reverse order of the array is" << endl;
//
//
//Confused on the code here
}
wow that was so simple and I was making it much more of a problem... Thanks, and yea I just noticed line 30, thanks. Just trying to figure stuff out ahead of time for class and learn stuff on my own before I get assigned something difficult. Thought I'd mess with arrays for a while and self teach : )
Thanks
this does not reverse an array unless they are in ascending order and have a difference of one. You are just creating a variable, assigning it a value of the last element, hoping the value of it is > 0 and then hoping that each consecutive item is one less in value.