Help with my array.

Our objective is to make a program that tells the user to input multiple numbers unless the user input 0, if the user inputs zero then the program will terminate, i already have the code but it seems there is an error.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 #include<iostream>
using namespace std;

int main()
{
  int num[0];
    for(int i=0; ;i++)
     {
       cout << "Enter a number: ";
       cin >> num[i];
          if(num[i] == 0)
             break;
      }
   system("pause");
}
Hey pal,you missed one thing....
You have to define cstdlib.h to use 'system()' functions....
I'll give more details in a minute...
Hey pal,you missed one thing....


No..

1. You can't define an array with zero elements (line 6). See:
http://www.tutorialspoint.com/cprogramming/c_arrays.htm

2. You can't (easily) dynamically grow a c-style array. You could use a vector instead of a c-style array.See:
http://www.cplusplus.com/reference/vector/vector/
I also included a 'exit(0)' after 'system(pause)' (in line 15).I use Windows 7 and the program keeps on running in the memory.

1
2
system("pause");
 exit(0);


Anyways its a good program to learn things (^_^) .
Yes,thats probably a good way to run virus programs in your computer.
And if it helps in any way,I will remember that.
Thnx mutexe for showing the article (^_^).
@mutexe
@LadyInRed7

Thank you for all the tips and articles, its helps me so much to understand more on how C++ works, much appriciated :D
Topic archived. No new replies allowed.