Array help

I'm trying to get the user to enter in 5 numbers into an array using a for loop. This is what I'm using.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "stdafx.h"
#include <iostream>

using namespace std;
int num[i];


int main(array<System::String ^> ^args)
{
   for (int i = 0; i <5; i++)
{ 
	cout<<"Enter in 5 numbers:";
	cin>>num[i];
	system("cls");

}

   system("pause") ;
    return 0;
}


for some reason it isn't working.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "stdafx.h"
#include <iostream>

using namespace std;
int num[i]; // you're trying to create an array of i integers
// except i isn't initialized


int main(array<System::String ^> ^args)
{
   for (int i = 0; i <5; i++)
{ 
	cout<<"Enter in 5 numbers:";
	cin>>num[i];
	system("cls");

}

   system("pause") ;
    return 0;
}
I changed i to 5 and it worked !
:)
Topic archived. No new replies allowed.