Hi , i write this code and i get error whene i run it !!! why i cant send a variable to array parameter ???

#include <iostream>
#include <conio.h>
using namespace std;
void main(){
	int a,b,c;
	cin>>a;
	cin>>b;
	c = a+b;
	int array[c];
	cout<<c;
	_getch();
}

i get this errors :

Error 1 error C2057: expected constant expression c:\users\mahdi\documents\visual studio 2008\projects\add number\add number\add.cpp 9 Add number

Error 2 error C2466: cannot allocate an array of constant size 0 c:\users\mahdi\documents\visual studio 2008\projects\add number\add number\add.cpp 9 Add number

Error 3 error C2133: 'array' : unknown size c:\users\mahdi\documents\visual studio 2008\projects\add number\add number\add.cpp 9 Add number

Array size must be a constant determinable at compile time (yours requires the user to enter numbers at run time). You can dynamically allocate your array with int * array = new int[c]; . Some compilers have extensions to their C compilers to do what you did but the results are not portable and non-standard.

Also, look at line 10. It is not going to give you the intended result. Loop through the elements to display them

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.