I try to vompile my program but what ever i do i get this error. I know where the problem is i just don't know how to solve it.
this is the declaration:
struct a0
{
char marka[50] = "AUDI";
char model[50] = "R8 SPYDER";
int obujam[50] = {5204};
int masa[50] = {1720};
int max_snaga_kw[50] = {386};
int max_snaga_ks[50] = {535};
int max_brzina[50] = {313};
float ubrzanje[50] = {4.1};
}a0;
and this is the problem:
if (player.front() == x)
{
player.pop();
cout<<"Your car is "<<a[x-1].marka<<" "<<a[x-1].model<<". It has "<<a[x-1].obujam[50]<<"ccm of Engine Displacement. It weights "<<a[x-1].masa[50]<<"kg. It's power is "<<a[x-1].max_snaga_kw[50]<<"kW and "<<a[x-1].max_snaga_ks[50]<<"KS. It has a top speed of ";
cout<<a[x-1].max_brzina[50]<<"km/h and it's acceleration from 0 to 100 km/h is "<<a[x-1].ubrzanje[50]<<"s.\n";
game.push(x);
problem is whit a[x+1].something(marka, model,...).
If you know how to resolve this please help.
Thanks in advance.
Like struct a0 i have them with different cars up to a55. So i was thinking off writing it like this within a loop. Every time loop would do its thing x would be one number up and it would print out different cars.
I'm not sure, but it might be that you're passing the array around wrongly.
Can you show:
- where you define a
- where you define game
- where you define x
- the signature of the function you're calling a[x-1] from
In general, you're more likely to get useful help if you can recreate a short, but complete program that still reproduces your error. "Short, Self Contained, Compilable, Example" http://sscce.org/
Also, you have 56 different structs named a0 to a55? Sounds like there's some ugly design flaw happening here...
struct car
{
string marka;
string model;
int obujam;
int masa;
int max_snaga_kw;
int max_snaga_ks;
int max_brzina;
float ubrzanje;
};
vector<car> allCars (50); // create a vector of 50 car objects
for (int i = 0; i < allCars .size(); ++i)
{
// do something with allCars[i], like set some values
}
If you're talking about the difference between mark and "mark", for example
string mark = "foo";mark here is the variable name, of type string.
string my_mark = "mark";"mark" is the string literal in this case, which is assigned to the variable called my_mark. "mark" is just a string literal, not the name of an actual object.
In his case: allCars[0] = { "mark", "model", 1, 2, 3, 4, 5, 6.5 }; "mark" and "model" are just place holders. You would need to change this to the car information that is needed.