Oh! I didn't see that. Thanks. Last question, how do I display the correct amount of tickets and total amount. I don't think I put the wrong data member.
Code:
cout << "--------------------------------" << endl << endl;
cout << " ADDITIONAL DETAILS " << endl;
cout << "--------------------------------" << endl;
cout << "You've purchase " << number << "Tickets" << endl;
cout << "Total amount : RM " << total << endl;
Code:
#include <iostream>
using namespace std;
class Ticket
{
private:
int number;
float price;
public:
friend class Student;
Ticket()
{
price = 10.00;
}
void setTickets()
{
cout << "Please enter number of tickets to purchase: ";
cin >> number;
}
};
class Student
{
private:
string id, name, purchase;
Ticket P;
public:
void setStudent()
{
cout << "\nEnter ID : ";
getline (cin, id);
cin.ignore();
cout << "Enter Name : ";
getline (cin, name);
cin.ignore();
}
void ticket_entry()
{
char y, n, yes, choice;
cout << "Do you want to purchase charity tickets? [Enter Y or N] :" ;
cin >> choice;
if (choice == 'y')
{
purchase = "yes";
P.setTickets();
}
if (choice == 'n')
{
cout << "---------No tickets purchase----------";
}
}
void display()
{
char yes, noo;
float total;
int number;
if (purchase == "yes")
{
cout << "--------------------------------" << endl;
cout << " STUDENT DETAILS " << endl;
cout << "--------------------------------" << endl;
cout << "ID : " << id << endl;
cout << "Name : " << name << endl;
cout << "--------------------------------" << endl << endl;
cout << " ADDITIONAL DETAILS " << endl;
cout << "--------------------------------" << endl;
cout << "You've purchase " << number << "Tickets" << endl;
cout << "Total amount : RM " << total << endl;
total = number * 10.00;
}
if (purchase == "noo")
{
cout << "--------------------------------" << endl;
cout << " STUDENT DETAILS " << endl;
cout << "--------------------------------" << endl;
cout << "ID : " << id << endl;
cout << "Name : " << name << endl;
cout << "--------------------------------" << endl << endl;
cout << " ADDITIONAL DETAILS " << endl;
cout << "--------------------------------" << endl;
cout << "You've not purchased any ticktes" << endl;
}
}
};
int main()
{
Student S1[3];
int i = 0;
S1[i].setStudent();
S1[i].ticket_entry();
S1[i].display();
return 0;
}