#include<iostream>
#include<string>
#include<iomanip>
#include<math.h>
usingnamespace 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.
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();.
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 ?
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.