This is the question
c) Develop a program (based on the flow chart) that uses a linked list data structure to keep the details of item and price. The program also must have two functions. One of the functions should accept arguments for the loyalty member data, while the other function accepts arguments for non-member customer data. Both functions should return the total payment.
Note: The program should check for input validation that does not accept negative numbers for any data.
and so far i manage to this
#include<iostream>
using namespace std;
void insert();
void member();
void nonmember();
struct node
{
char item;
int price;
node *next;
};
node *newptr;
node *head;
int main()
{
char x,rcn,cashcard;
int payment, yn;
cout<<"Customer has royalty member card or not ? ( 1 for Yes / 0 for No )"<<endl;
cin>>yn;
if(x=1)
{
member();
cout<<"Royalty Card Number : "<<rcn<<endl;
cout<<"Total Payment : "<<payment;
cout<<cashcard;
void member()
{
char rcn , cashcard , Cash , Card;
int total , payment , one;
cout<<"Please input royalty card number : "<<endl;
cin>>rcn;
cout<<"Press 1 to add item into the card"<<endl;
cin>>one;
while(one=1)
{
insert();
}
total = 0;
while(newptr)
{
total += newptr->price;
node= newptr->next;
}
if (total<100)
{
payment=total;
}
else if (total>=100 && total<301)
{
payment = 0.95*total;
}
else
{
payment=0.9*total;
}
cout<<"Payment type ? ( Cash / Card )"<<endl;
cin>>cashcard;
if(cashcard==Cash)
{
cout<<"The balance is RM "<<endl;
}
else if (cashcard==Card)
{
cout<<"All Payment has been deducted from your bank account"<<endl;
}
}
void nonmember()
{
char one , cashcard ,Cash , Card;
int total , payment;
cout<<"Press 1 to add item into the card"<<endl;
cin>>one;
while (one==1)
{
insert();
}
total = 0;
while(newptr)
{
total+= node->price;
node = node->next;
}
payment=total;
cout<<"Payment type ? ( Cash / Card )"<<endl;
cin>>cashcard;
if(cashcard==Cash)
{
cout<<"The balance is RM "<<endl;
}
else if (cashcard==Card)
{
cout<<"All Payment has been deducted from your bank account"<<endl;
}
newptr = new node;
cout<<"\nPlease enter a item bought : ";
cin>>newptr->item;
newptr->next = NULL;
cin>>newptr->price;
newptr->next = NULL;
if(head == NULL){
head = newptr;
}
else{
// a loop to move prev and cur along the list and stop at appropriate place
// to insert a new element
while(cur != NULL && newptr->item > cur->item){
prev = cur;
cur = cur->next;
}
//insert in front of the list
if(prev == NULL){
newptr->next = cur;
head = newptr;
}
else {
//coding to insert at the middle or the end of the list
newptr->next = cur;
prev->next = newptr;
}
}
}
And its look like i get error on While under void member and nonmember.
what im trying to do there is sumarize all the price inside the linked list.