I have created a class that allows the user to input their mailing address, order date, type of cookie ordered and the quantity. I'm taking things step by step and have got the program running, but I can't get the comparing part to work. It will accept any string as a flavor. After I get the compare part, I need to be able to change code to overload the I/O stream operators so that the objects may be used in standard input and output statements.

I'm not sure what all part of the code everyone will need to see, but I'm going to post the parts I believe are needed for what I'm trying to do.

The program is acting like I'm not calling it correctly, but I have called it the same as the other methods and have everything set up as far as structure the same.

class CookieOrder
	string flavors[] = {"Chocolate Chip", "Peanut Butter", "Sugar", "Pecan", "Candy",};
	CookieOrder(string default_customerName, string default_address1, string default_city,
				string default_state, int default_zip, int default_orderMonth, int default_orderDay,
				string default_cookieOrdered, int default_quantity);
	void input();
	void output();
	void set(string new_customerName, string new_address1, string new_city,
			 string new_state, int new_zip, int new_orderMonth, int new_orderDay,
			 string new_cookieOrdered, int new_quantity);
	string get_customerName();
	string get_address1();
	string get_city();
	string get_state();
	int get_zip();
	int get_orderMonth();
	int get_orderDay();
	string get_cookieOrdered();
	int get_quantity();

	string::iterator it;
	string check_cookieOrdered();
	void check_quantity();
	string customerName;
	string address1;
	string city;
	string state;
	int zip;
	int orderMonth;
	int orderDay;
	string cookieOrdered;
	int quantity;

This next part is part of the input()

cout << "Enter the Order Day: ";
	cin >> orderDay;
	cout << "Enter the cookie ordered: ";
	cin >> cookieOrdered;
	cout << "Enter the quantity: ";
	cin >> quantity;
	cout << endl;

This is the check_cookieOrdered() that I need help to get to work

string CookieOrder::check_cookieOrdered()
string::iterator it( cookieOrdered.begin());  

		if( cookieOrdered.length() > 0 )
			cookieOrdered[0] = toupper(cookieOrdered[0]);

		while(++it != cookieOrdered.end())

			*it = tolower((unsigned char)*it);

		for( size_t i = 1; i < cookieOrdered.length(); i++)
			if( cookieOrdered[i-1] == ' ' )
				cookieOrdered[i] = toupper(cookieOrdered[i]); 

		for(int i=0;i<6;i++)  //Checks to see if input matches those of possible inputs.
				valid_option = true;

				cout << "Invalid Flavor. Try again.\n\n"; 

			return cookieOrdered;

Any assistance would be greatly appreciated. I'm under a tight time restriction for the due date but have most of the program working as far as I can tell and only need assistance in finishing it up.


You can just simply write this: if( cookieOrdered == flavors[i] ) , assuming flavors is an array or vector of strings/character arrays..

Could also be: cookieOrdered = ""; line 8: There is really no point in using an iterator in that function. Just use a loop similar to line 13.

line 8 of the second code snippet: That is ignoring the return value of check_cookieordered().

I changed what you said and it still isn't working. So I placed in a random cout statement just to test if the method was even being called and it didn't print out thus saying that the method isn't even being called and/or when called it doesn't do anything.

I know that it will be a little long, but do you want me to post my full code and/or PM it?

That or other ideas? I'm still looking at it, but everything seems to be in order.

Thanks for your assistance.

I stayed after class and with the assistance of the prof, I have everything working other than the overloading of the output operators. Going to look that up and hopefully have the proj finished 2night.

Thanks for your assistance. I greatly appreciate it.

I'm at a complete loss. I've looked over everything but can't make heads or tails of it.

friend ostream& operator<< (ostream& outs, const CookieOrder& order);  
friend istream& operator>> (istream& ins, CookieOrder& order);

that right?

>>that right?
Yes, now put that in the public section of a class.

Have set to following after where listing of public and private members and before main

ostream & operator<< (ostream& outs, CookieOrder& order);
istream & operator>> (istream& ins, CookieOrder& order);

then only errors I get when setting method headers for respective methods within the definitions, I only get these errors in respect to the input method :

(92) : error C2065: 'customerName' : undeclared identifier
(94) : error C2065: 'address1' : undeclared identifier
(96) : error C2065: 'city' : undeclared identifier
(98) : error C2065: 'state' : undeclared identifier
(100) : error C2065: 'zip' : undeclared identifier
(102) : error C2065: 'orderMonth' : undeclared identifier
(104) : error C2065: 'orderDay' : undeclared identifier
(107) : error C3861: 'check_cookieOrdered': identifier not found
(112) : error C3861: 'check_cookieOrdered': identifier not found
(115) : error C2065: 'cookieOrdered' : undeclared identifier
(118) : error C2065: 'quantity' : undeclared identifier
(119) : error C3861: 'check_quantity': identifier not found

I don't know how to set up the input methods b/c I dont want to set the cookie type or quantity until the program runs the methods to check for valid input from the user

Problem Solved.

Thanks for all of your input and assistance. I greatly appreciate it.