Can't figure out my error

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
  #include<iostream>
#include<string>
#include<iomanip>
#include<math.h>
using namespace std;
struct car
{
       char brand[41];
       char colour[21];
       float rent;
       char code[9];
};
void InputCarInfo(car p)
{
     char date[3];
     cout<<"Input the brand of the car: ";
     cin>>p.brand;
     cin.ignore();
     cout<<"Input the colour of the car: ";
     cin>>p.colour;
     cin.ignore();
     cout<<"Input the rental price: ";
     cin>>p.rent;
     cout<<"Input the type of the car as they are : \n";
     cout<<"1-Small, 2-Compact, 3-Medium, 4-Van, 5-Jeep \n";
     cin>>date;
     p.code[0]=date[0];
     cout<<"Input the date the rent is due: \n";
     cout<<"Day:";
     cin>>date;
     p.code[1]=date[0];
     p.code[2]=date[1];
     cout<<"Month: ";
     cin>>date;
     p.code[3]=date[0];
     p.code[4]=date[1];
     cout<<"Year: ";
     cin>>date;
     p.code[5]=date[0];
     p.code[6]=date[1];
}
void OutputCars(car p)
{
     cout<<"All of the cars in this dealership are : ";
     cout<<"Brand: ";
     cout<<p.brand;
     cout<<"Type(class): ";
     switch(p.code[0])
     {
                      case '1':cout<<"Small";break;
                      case '2':cout<<"Compact";break;
                      case '3':cout<<"Medium";break;
                      case '4':cout<<"Van";break;
                      case '5':cout<<"Jeep";break;
     }
     cout<<"Colour: ";
     cout<<p.colour;
     cout<<"Rental price: "<<setprecision(2)<<setiosflags(ios::fixed)<<p.rent;
     cout<<"The date the rent is due is : ";
     cout<<p.code[1]<<p.code[2]<<"."<<p.code[3]<<p.code[4]<<"."<<p.code[5]<<p.code[6]<<".";
}
int main()
{
    car dealership[200];
    int numberCars;
    cout<<"Input the number of cars in the dealership: ";
    cin>>numberCars;
    for(int i=0;i<numberCars;i++)
    InputCarInfo(dealership,[i]);
    cout<<"_______________________________________"<<endl;
    for(int i=0;i<numberCars;i++)
    OutputCars(dealership,[i]);
    return 0;
    system("pause");
}

Hi guys, I keep getting the following error :
1
2
69 blalalalalallaal expected primary-expression before '[' token 
72 blalalalalallaal expected primary-expression before '[' token 

Can anyone tell me what is wrong and why does it keep giving me this error? Thank you.
Last edited on
Get rid of the commas on lines 69 and 72.
Now I get the following errors :
1
2
3
4
69  expected primary-expression before '[' token 
70  expected `;' before "cout" 
72  expected primary-expression before '[' token 
73  expected `;' before "return" 

I don't really think it's the commas ..
I don't really think it's the commas ..

It really is the commas. Although, if you've made some other change to the code in the interim, it's quite possible that you've introduced an additional problem.

InputCarInfo should take it's parameter by reference, by the way.
1. The error you are receiving has something to do with the inability to convert car* to car.

2. You've probably heard this before but you really shouldn't use system("pause"); as it is very inefficient and you also did not include it's library. Instead you should use cin.get();.

Hope this helps.
Well can anyone tell me how to call the void functions the correct way ? That's how he did it in class and now when I tried running the program from class it gave me the same error .. Can anyone help please ?
To call a function it's functionName();.

So in your case it would be OutputCars(car p) for example.
In this case it gives me :
1
2
69 expected primary-expression before "p" 
75 expected primary-expression before "p"
Last edited on
Make sure you open a bracket after your for loops and then close the bracket once the loop is over. Makes it easier on the eyes when trying to find an issue.
Topic archived. No new replies allowed.