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
{
public:
string flavors[] = {"Chocolate Chip", "Peanut Butter", "Sugar", "Pecan", "Candy",};
CookieOrder();
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();
private:
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;
check_cookieOrdered();
cout << "Enter the quantity: ";
cin >> quantity;
check_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.
if(!cookieOrdered.compare(flavors[i]))
{
valid_option = true;
break;
}
if(!valid_option)
{
cout << "Invalid Flavor. Try again.\n\n";
cookieOrdered.clear();
continue;
}
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.