For example, I entered :
Enter a number: 5
Enter element 0 values: 10
Enter element 1 values: 20
Enter element 2 values: 30
Enter element 3 values: 40
Enter element 4 values: 50
Enter element 5 values: 70
In the last part, I just want the Element values to appear like this.
Element values are: 10 20 30 40 50 70
but its showing this instead :
Element values are: 70 70 70 70 70 70
So the last value, I entered is the one that repeatedly appears in the "Element values"
So please help me with this code, I cant seem to find the solution.
Thanks !
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include<iostream>
using namespace std;
int main ()
{
int arrsize = 0;
cout<<"Enter a number: ";
cin>>arrsize;
int num[arrsize];
for (int xox = 0; xox <= arrsize; xox++)
{
cout<<endl;
cout<<"Enter element "<<xox<<" values: ";
cin>>num[arrsize];
}
cout<<endl;
cout<<"Element values are: ";
for (int xox = 0; xox <= arrsize; xox++)
{
cout<<num[arrsize]<<" ";
}
}
|