Reputation: 683
I`m having some errors in my c++ program. I need to create out of 2 sorted list, a 3-rd which is sorted out of the first 2.
void arrayInp()
/* Create 2 vectors by the length defined by the user*/
{
int a,b,c,d,i,j;
Array A,B; /* HERE i get the error used varaibls, why?*/
int rez[20];
cout<<"enter length of the first array: ";
cin>>a;
cout<<"enter length of the second array: ";
cin>>b;
cout<<"insert first array:";
for (i=0;i<=a;i++)
cin>>c;
A.els[i]=c;
cout<<", ";
cout<<"insert second array:";
for (j=0;j<=a;j++)
cin>>d;
B.els[j]=d;
cout<<", ";
}
The header i imported is containing:
const int dim = 10;
struct Array
{
int n;
int els[dim];
};
Thank you for your help
Upvotes: 0
Views: 3384
Reputation: 299880
If you are a beginner, try and get Clang to compile your code. It puts a particular emphasis on digestible error messages.
If you cannot use it, you still have the online version, though it's limited in terms of dependencies obviously.
/tmp/webcompile/_1981_1.cc:18:5: warning: unused variable 'rez' [-Wunused-variable]
int rez[20];
^
1 warning generated.
You can see, in general, for diagnosis:
And for this particular warning: the name of the unused variable is actually shown.
Do yourself a favor, get a friendly compiler ;)
Upvotes: 1
Reputation: 46569
rez
is the unused variable, not A
or B
.
And you have several other errors. The braces for one thing. And you ask for more input parameters than the user is prepared to give (in (i=0;i<=a;i++)
). And you use a
for an upper boundary instead of b
in the second block. Copy and paste error?
Upvotes: 0
Reputation: 258618
The warning possibly comes from rez
, which you don't use.
First time I looked at the code, I could tell you're coming from python. The code results in undefined behavior (possibly, depending what indexes get to be):
int a,b,c,d,i,j;
Array A,B; /* HERE i get the error used varaibls, why?*/
//...
for (i=0;i<=a;i++)
cin>>c;
A.els[i]=c;
cout<<", ";
See the error?
for (i=0;i<=a;i++)
{
cin>>c;
}
A.els[i]=c;
cout<<", ";
How about now?
Upvotes: 3