Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int PCPurchase()
- {
- struct customer cust;
- system("color 0A");
- char laptop[100];
- double total_bill;
- const double TAX=0.06;
- system("cls");
- cout << setfill ('-') << setw (55) << "-" << endl;
- cout << "ttCustomer Dashboard" << endl;
- cout << setfill ('-') << setw (55) << "-" << endl;
- fptr=fopen("laptop.txt","ab+");
- cout << "Available laptops: " << endl;
- rewind(fptr);
- while(fread(&PC,sizeof(PC),1,fptr)==1)
- {
- cout << endl << "Laptop company and name: ";
- cout << PC.laptopcompany << endl;
- cout << "RAM: ";
- cout << PC.RAM << endl;
- cout << "Processor: ";
- cout << PC.Processor << endl;
- cout << "Price: RM";
- cout << PC.price << endl;
- }
- cout << "nPress any key to continue purchase" << endl;
- getch();
- fflush(stdin);
- getInfo(cust); //get information of customer
- cout << "Enter the laptop company and name you want to buy: " << endl;
- cout << "(Type 'RETURN' if you do not want to purchase)" << endl << endl;
- gets(laptop);
- rewind(fptr);
- while(fread(&PC,sizeof(PC),1,fptr)==1)
- {
- if(strcmpi(PC.laptopcompany,laptop)==0)
- {
- cout << setfill ('-') << setw (55) << "-" << endl;
- cout << "tYou have selected" << endl;
- cout << setfill ('-') << setw (55) << "-" << endl;
- cout << "Laptop company and name: ";
- cout << PC.laptopcompany << endl;
- cout << "RAM: ";
- cout << PC.RAM << endl;
- cout << "Processor: ";
- cout << PC.Processor << endl;
- cout << "Price: ";
- cout << PC.price << endl;
- total_bill=PC.price+(PC.price*TAX);
- cout << setfill ('-') << setw (55) << "-" << endl;
- cout << fixed << showpoint << setprecision (2);
- cout << "Name: "<< cust.name << endl; // struct output
- cout << "Email: "<< cust.email << endl;
- cout << "Phone Number: " << cust.number << endl;
- cout << "Your total bill (including 6% tax): RM" << total_bill << endl;
- cout << setfill ('-') << setw (55) << "-" << endl;
- cout << endl << "tPress 1 to return to main screen!";
- cout << endl << "tPress 2 to quit the program!";
- char afterpurchase;
- afterpurchase=getche();
- if (afterpurchase=='1')
- {
- fclose(fptr);
- main();
- }
- else
- exit_system();
- }
- else if(strcmpi("RETURN",laptop)==0)
- main();
- else
- {
- cout << endl << "tNot available!" << endl;
- cout << "tPress A to try again or B to return to main menu" << endl;
- char choice1;
- choice1=getche();
- choice1=toupper(choice1); // Transform to uppercase
- switch (choice1)
- {
- case 'A': fclose(fptr);
- PCPurchase();
- break;
- default : fclose(fptr);
- main();
- break;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment