Hi. I am trying to input values from a user and put them in a linked list. Some how when I display the values that the user inputs, they are both show up under one variable. ie. user inputs $3 and then inputs $5 for next variable. however, when i display, it displays both entered vlues under first variable. attached is code and picture of running program.
I don't know what the problem is, but when I display the values that I input from the users, i.e. coupon value and minimum to spend rule amount, it just displays both the values as one number under coupon value. i have attached a picture of the screen shot as well as my code.

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;
    }
}

void coupons::display_all()      //display function
  {  node *temp = head;
     cout << endl;
     if (temp == NULL)
       cout << "There are no coupons!" << endl;
     else
       { while (temp != NULL)
       {  // Display details for what temp points to
          cout<< left << setw(5) << "Name: " << temp->name << setw(5) << " Description: "<< setw(5) << temp->category << " Discount $" << temp->discount << setw(5) << temp->spend << " Rule $" << setw(5) << " Expires " <<temp->mm << "/" << temp->dd << "/"<< temp->yyyy; //display format
          if (temp == current)
        cout << " <-- Current Coupon";
              cout << endl;
          temp = temp->next;

       }
     cout << "End of Coupons!" << endl;
       }

Please refer to line 77. Looks like the two numbers are being printed together and appears like a single entity.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.