charactar array

hi guys,I really don't know what's the wrong with this code,it should prompt the user to enter any number but -1, and store it in const int size so as to enter charactar array and display it on the screen.
if anyone could help me and tell me what's the wrong with it and what to do ,I'll be thankfull.
#include<iostream>
using namespace std;
void main()
{
while(true)
{
int x;
cin>>x;
if(x==-1)
break;
else
{
const int y=x;
char arr[y];
cin>>arr;
cout<<arr;
}
}
}
closed account (9wX36Up4)
it could be because of void main() use just main() i tried it is working (and i use DevC++)
well,maybe,but it gives me the following errors:
1.unknown arr size
2.illegal size of arr 0
closed account (D80DSL3A)
nayef wrote:
I really don't know what's the wrong with this code...

The compiler produces error messages to help you with this.

What do they say?

There may be problems with the way you are trying to create a variable length array.
Also, a constant (as in const int y) must be assigned to a CONSTANT, not a variable. The value is determined at compile time, not run time.

Try using the string class. This is the easy way to get variable length strings.
You will need to #include <string> for this.

Standard compliant form for the main()?
1
2
3
4
5
int main()
{
	// code here
	return 0;
}
thank's fun2code you really helped me
Topic archived. No new replies allowed.