Hi. I am kind of having trouble with some functions. Basically, I know how to write out functions using void and no return, but for this problem I am working on, I have to use int myfunction(something&) instead of void myfunction(). Can anyone please lead me in the right direction as to what I should be doing?? I have my code for my function below.
I want it such that, its int add_coupon(coupon&) instead of void add_coupon()
here is my code so far:
void node::add_coupon()
{
char temp[201];
char temp2[201];
cout << "Adding a new coupon....."<<endl;
cout << "Enter the name of the store coupon: ";
cin.get(temp,200,'\n');
cin.ignore();
name = new char[strlen(temp)+1];
strcpy(name,temp);
cout << "Enter description: ";
cin.get(temp2,200,'\n');
cin.ignore();
category = new char[strlen(temp2)+1];
strcpy(category,temp2);
cout << "Enter the coupon discount amount: $";
cin >> discount;
cin.ignore();
cout << "Enter the spend amount before coupon discount can be applied: $";
cin >> spend;
cin.ignore();
cout << "Enter the coupon expiration date in MM/DD/YYYY format: ";
cout << "Enter MM-> ";
cin >> mm;
cin.ignore();
cout << "Enter DD-> ";
cin >> dd;
cin.get();
cout << "Enter YYYY-> ";
cin >> yyyy;
}
/*Function for creating my linked list. This creates the list in sorted order
alphabetically based on the name of the coupon's store.
*/
void coupons::add_coupon()
{
current = head;
node* temp = new node;
temp->add_coupon();
temp->next = NULL;
if(!head)
head = temp;
else if(strcmp(head->name,temp->name)>0)
{
temp->next = head;
head = temp;
}
else
{
node *current = head->next;
node *prev = head;
while(current !=NULL && strcmp(temp->name, current->name)>0)
{
prev = current;
current = current->next;
}
temp->next = current;
prev->next = temp;
}
}