No operator matches these operands in the for loop

Hello ,

I am trying to get this program to work using a for loop. My problem is that the cin >> inside the for loop says that "no operator matches these operands" .
I would like to use a for loop for all the setter functions that I have in the main function . One more question is how to relate the information that I get from my setter function to the displayCars user defined function defined outside of class.

This is the code :
#include<iostream>
#include<ctime>
#include<string>
#include<iomanip>
using namespace std;

class car
{
private:
string carInformation;
string manufacturer;
string model;
string type;
double price;
int serialNo;
int warranty;
double rebate;

public:
car();
car (string Info_manufacturer,string Info_model,string Info_type, double Info_price,int Info_serialNo,int Info_warranty,double Info_rebate); //constructor
//member function prototypes
//void print();

void setmanufacturer(string Info_manufacturer);
void setmodel(string Info_model);
void settype(string Info_type);
void setprice(double Info_price);
void setserialNo(int Info_serialNo);
void setwarranty(int Info_warranty);
void setrebate(double Info_rebate);

string getmanufacturer();
string getmodel();
string gettype();
double getprice();
int getserialNo();
int getwarranty();
double getrebate();

void displaycars();


};
void displaycars(string manufacturer,string model,string type,double price, int serialNo, int warranty, double rebate);


int main()
{

string input_manufacturer;
string input_model ;
string input_type;
double input_price = 0.00 ;
int input_serialNo = 0 ;
int input_warranty = 0 ;
double input_rebate = 0.00 ;

cout<< " This pogram takes in information about your car and displays it on the screen. Below is an example that has the details of car1. You will have to input the \n data to fill in the information about car2.\n\n\n\n";

cout<<endl<<endl<<endl;
car c [2] ;
for ( int i = 0 ; i <= 2 ; i++)
{
cin >> c[0].setmanufacturer (input_manufacturer);
}

c[0].settype(input_type);
c[0].setmodel(input_model);
c[0].setprice(input_price);
c[0].setserialNo(input_serialNo);
c[0].setwarranty(input_warranty);
c[0].setrebate(input_rebate);

cout << " Please enter the information for car 2 :"<<endl<<endl;

c[1].setmanufacturer (input_manufacturer);
c[1].settype(input_type);
c[1].setmodel(input_model);
c[1].setprice(input_price);
c[1].setserialNo(input_serialNo);
c[1].setwarranty(input_warranty);
c[1].setrebate(input_rebate);


cout << " Press on any key to look at the information \n\n\n\n\n\n\n\n";
system("pause");
system("cls");
c[0].displaycars();
c[1].displaycars();
//car1.print();
//car2.print();

cout<<"\n\n\n\n\n\n\n"<<endl;
displaycars( input_manufacturer,input_model, input_type, input_price,input_serialNo,input_warranty , input_rebate );
return 0;

}

car:: car()
{
manufacturer = " " ;
model = " ";
type = " ";
price = 0.00;
serialNo = 0;
warranty = 0;
rebate = 0.00;
}

car :: car (string Info_manufacturer,string Info_model,string Info_type, double Info_price,int Info_serialNo,int Info_warranty,double Info_rebate)
{


manufacturer = Info_manufacturer ;
model = Info_model;
type = Info_type;
price = Info_price;
serialNo = Info_serialNo;
warranty = Info_warranty;
rebate = Info_rebate;


}

//member function definitions
/*
void car :: print()
{
cout << carInformation;
}
*/





void car :: setmanufacturer(string Info_manufacturer)
{
cout << " Please enter the information for Manufacturer : " ;
cin >> Info_manufacturer;
cout<<endl<<endl;
manufacturer = Info_manufacturer;
}
void car :: settype(string Info_type)
{
cout << " Please enter the information for Type : " ;
cin>>Info_type;
cout<<endl<<endl;
type = Info_type;
}

void car :: setmodel(string Info_model)
{
cout << " Please enter the information for Model : " ;
cin >>Info_model;
cout<<endl<<endl;
model = Info_model;
}



void car :: setprice(double Info_price)
{
cout << " Please enter the information for Price : " ;
cin>>Info_price;
cout<<endl<<endl;
price = Info_price;
}

void car :: setserialNo(int Info_serialNo)
{

cout << " Please enter the information for Serial Number : " ;
cin>>Info_serialNo;
cout<<endl<<endl;
serialNo = Info_serialNo;
}

void car :: setwarranty(int Info_warranty)
{

cout << " Please enter the information for Warranty : " ;
cin >>Info_warranty;
cout<<endl<<endl;
warranty = Info_warranty;
}

void car :: setrebate(double Info_rebate)
{
cout << " Please enter the information for Rebate : " ;
cin >> Info_rebate;
cout<<endl<<endl;
rebate = Info_rebate;
}




string car :: getmanufacturer()
{
return manufacturer;
}

string car :: getmodel()
{
return model;
}

string car :: gettype()
{
return type;
}

double car :: getprice()
{
return price;
}

int car :: getserialNo()
{
return serialNo;
}

int car :: getwarranty()
{
return warranty;
}

double car :: getrebate()
{
return rebate;
}

void car :: displaycars()
{
car c[2];;
cout<<" Information from funtion prototype inside of class"<<endl<<endl;
cout << " \t\t\t\tCAR " <<endl<<endl;
cout <<endl<<endl<< " Manufacturer : \t\t" << manufacturer <<endl<<endl;
cout<< " Model : \t\t\t"<<model<<endl<<endl;
cout<<" Type : \t\t\t" << type<<endl<<endl;
cout << " Price ($): \t\t\t" <<price<<endl<<endl;
cout<<" Serial Number : \t\t" << serialNo<<endl<<endl;
cout <<" Warranty (yrs) : \t\t" <<warranty<<endl<<endl;
cout << " Rebate (%) : \t\t\t"<< rebate<<endl<<endl;
}



void displaycars(string manufacturer,string model,string type,double price, int serialNo, int warranty, double rebate)
{
car c[2];
cout<<" Information from funtion prototype outside of class"<<endl<<endl;
cout << " \t\t\tCAR 1 \t\t CAR 2 " <<endl<<endl;
cout <<endl<<endl<< " Manufacturer : \t\t" <<manufacturer << "\t\t"<<manufacturer <<endl<<endl;
cout<< " Model : \t\t\t"<<model<<"\t\t"<<model<<endl<<endl;
cout<<" Type : \t\t\t" << type<<"\t\t"<<type<<endl<<endl;
cout << " Price ($): \t\t\t" <<price<<"\t\t"<<price<<endl<<endl;
cout<<" Serial Number : \t\t" << serialNo<< "\t\t" <<serialNo<<endl<<endl;
cout <<" Warranty (yrs) : \t\t" << warranty<< "\t\t" << warranty<<endl<<endl;
cout << " Rebate (%) : \t\t\t"<< rebate<<"\t\t"<< rebate<<endl<<endl;

}



1>
1>
My problem is that the cin >> inside the for loop says that "no operator matches these operands" .

If you are using the shift operator on cin, you need to provide a variable which is either a data type or a string.

The following should do nicely:
1
2
3
4
5
6
for ( int i = 0 ; i <= 2 ; i++)
{
    string input_manufacturer;
    cin >> input_manufacturer;
    c[0].setmanufacturer (input_manufacturer);
}

how to relate the information that I get from my setter function to the displayCars user defined function defined outside of class.

Get all your values using the get- functions for your car class and then call displayCars with all the values. Personally, I would have just written a displayCars member function and called it for each car in your array.
Thank you for your reply.

Yes I have done that , but the assignment requires me to define a user defined member function outside of class and then display the information which is being displayed by the member function inside the class. I am not sure how to do that.

So the last function definition where I am defining the displaycars with all the arguments , I am basically displaying the information about those arguments from int main where I have defined those variables , but I need to get the information that I enter through the setter and the getter functions. Is there a way to do that ?
Topic archived. No new replies allowed.