Re: More help with arrays?
Other than the fact that it doesn't compile, it seems fine to me.
But:
Why do view and delete return a weapon? Not only is this useless, but the fact that you are returning from invalid memory makes your program crash.
Your program does not compile because of the following:
Code:
//DELETING DATA
int n=a; //here a is not defined, it was part of a loop. Maybe you want n = b?
for( n; n<size; n++)
{
add[n]=add[n+1] //needs a ;
}
}
Code:
int b=0;
bool out=true;
//QUERY
for (int a=0; a<size|| out; a++)
{
if (add[a].id==weapon_id)
{
cout<< setw(15)<< add[a].id<< " "<<add[a].name<< " "<<add[a].quantity<< endl;
cout<< "This is teh weapon you wanna delete at row "<< a << endl;
out=false;
//b = a;?
}
}
Weren't you planning to do something with b here? Maybe b was the value you wanted to assign to n?
Re: More help with arrays?
I didn't compiled, but main issue looks to be with the array of user defined size.
You can't do: cin>> size; weapon add[size]; (any recent compiler will complain about this).
For that you will need a dynamicaly allocated array, declare it like this:
weapon *add = new weapon[size];
Don't forget to delete it (when you are done with it) like this:
delete[] add;
Re: More help with arrays?
You have a few errors in syntax. I didn't even bother checking behaviour.
int n = a;
doesn't work because the scope of a is the previous for loop so after the loop a no longer exists and so cannot be assigned to n. One possible fix for that is to take the declaration of a out of the loop.
add[n]=add[n+1]
missing semicolon.
cout<< "Enter size of record"<< endl;
cin>> size;
weapon add[ size];
Impossible to do that. when you declare an array its size must be a constant. User input is not constant. How does your compiler know how much space to reserve on the stack for an array of undeterminate size?
There maybe more errors. Only had a cursory glance. fix those and see how much better things are.
BTW Please use [code][/code] tags around code blocks.