0
votes

I'm currently in a school project where I am in need of using both array and looping statements with the C++ Win32 console application. But I had this idea where I want to use variables as data inside array. Here's an example:

given[4]={a,b,c,d};

In here, I used variables inside the array. With the use of cin, I could manually type the value whenever the console is running. But usually this error occurs whenever I try to debug and run the code.

1>c:\users\acer\documents\visual studio 2010\projects\ttestosektse\ttestosektse\ttestosektse.cpp(15): error C2065: 'aa' : undeclared identifier 1>c:\users\acer\documents\visual studio 2010\projects\ttestosektse\ttestosektse\ttestosektse.cpp(15): error C2065: 'bb' : undeclared identifier 1>c:\users\acer\documents\visual studio 2010\projects\ttestosektse\ttestosektse\ttestosektse.cpp(15): error C2065: 'cc' : undeclared identifier 1>c:\users\acer\documents\visual studio 2010\projects\ttestosektse\ttestosektse\ttestosektse.cpp(15): error C2065: 'dd' : undeclared identifier

If you ever need all of the codes, here they are:

int b=0;
int n=1;
int all;
string name[4]={"X1","X2","Y1","Y2"};
int given[4]={aa,bb,cc,dd};
while(n<=4)
{
    cout<<"Enter "<<name[b]<<": ";
    cin>>given[b];
    n=n+1;
    b=b+1;
}

return 0;

Are there any possible solutions for this? Thanks in advance. :)

1
You need to declare aa,bb,cc,ddJLev
In your case, aa,bb,cc and dd are all undeclared variables.Asesh
Sadly I get a "Debug error! The variable aa is being used without being initialized" whenever I run the console. :(Joaquin Luis B. Basbacio
@JoaquinLuisB.Basbacio the message is pretty clear. You must initialize the variable before you use it. The initial content of a local variable is indeterminate. Show more code, it's unclear how you use these variables. Read this: minimal reproducible exampleJabberwocky
It isn't quite clear what you are trying to do. Arrays and variables and loops are your solution, but what is your problem?n. 1.8e9-where's-my-share m.

1 Answers

0
votes

I have finally found the solution. As for the given[] array, instead of adding the variable inside them; I added zeroes. each of the array data will be considered as a variable.

(e.g: given[0] as X1, given[1] as X2)

So each of the array data will be changed by cin>>given[b].