Hey, I'm studying c++ programming at university at the moment.
We've recently moved onto arrays - which I understand mostly.
I have no problem displaying information from an already set array, e.g.
int storage[5] = {1,2,3,4,5};
However, I'm having problems when adding my own data to an array within the program.
For example, I'd like my program to say:
"Enter a Number: "
And then when I enter a number, it is added to the array, and then the whole array is displayed showing all of the numbers added.
This is my code so far:
#include <iostream>
using namespace std;
int main()
{
int storage[15]; // Array to store up to 15 integers.
int x; // Variable x, which becomes 0 in the for loop.
int number; // This will be the number the user enters.
// Do while loop repeats until I enter 1000.
// The program asks the user what number they would like to enter.
// The number then should be entered to the storage array, and displayed.
do {
cout << "Enter number: ";
cin >> number;
cout << endl << endl;
for (x = 0; x<15; x++){
storage[x] = number;
cout << storage[x] << " " << endl;
break;
}
} while (number != 1000);
return 0;
}
For some reason, it only displays the most recent number added, and not the whole array. I've been trying to figure this out for hours now, any help would be much appreciated!
Thank you.