Escribir un programa que ofrezca las siguientes opciones:
1. Client data
2. Sale data
3. Invoice
4. Totals
5. Restart
0. Exit
El programa mostrará el menú hasta que el usuario elija la opción.. Por ahora lo que llevó es esto. Seguramente haya mucha cosa innecesaria. Si es así, me lo podéis decir. Espero respuesta.
Muchas gracias de antemano.
Código
#include <iostream> #include <string> using namespace std; #include <cctype> #include <iomanip> int menu(); double cost(int descPercentage, double total, double final, double amountDisc, double amountVAT); int main() { int option; int units; int readCost; int readMenu; int descPercentage; const int VAT = 21; const int DISCOUNT = 15; double price; double total; double readcost; double final; double amountDisc; double amountVAT; bool sale = false; bool client = false; char discount; string product; string name, nif, address; cout << "1. Client Data" << endl; cout << "2. Sale Data" << endl; cout << "3. Invoice" << endl; cout << "4. Totals" << endl; cout << "5. Restart" << endl; cout << "0. Exit" << endl; cout << "Option: "; cin >> option; cout << endl; switch (option) { case 1: if (client == false) { cout << "Client Name: "; cin.sync(); getline (cin, name); cout << "Client NIF: "; getline (cin, nif); cout << "Client Address: "; getline (cin, address); cout << client; cout << endl; } case 2: if (sale == true) { readMenu = menu(); cout << "Product Name: "; cin.sync(); getline (cin, product); cout << "Product Price: "; cin >> price; cout << "Discount (y/n): "; cin >> discount; discount = toupper(discount); if (discount == 'Y') { descPercentage = DISCOUNT; } else { descPercentage = 0; } cout << "Units: "; cin >> units; sale = true; cout << sale; cout << endl; } else if (sale != false){ cout << "No sale data!" << endl; cout << endl; readMenu = menu(); } case 3: if (client == false) { cout << "No client data!" << endl; cout << endl; readMenu = menu(); client = false; cout << client; } else { readMenu = menu (); cout << endl << "Invoice:" << endl; cout << setw(50) << right << name << endl; cout << setw(50) << right << nif << endl; cout << setw(50) << right << address << endl << endl; readMenu = menu (); client = true; cout << client; } case 4: if (sale == false) { cout << "No sale data!" << endl; cout << "1. Client Data" << endl; cout << "2. Sale Data" << endl; cout << "3. Invoice" << endl; cout << "4. Totals" << endl; cout << "5. Restart" << endl; cout << "0. Exit" << endl; cout << "Option: "; cin >> option; sale = false; cout << sale; } else { readcost = cost(descPercentage, total, final, amountDisc, amountVAT); cout << "Product: " << product << endl; cout << setw(40) << left << "Unit Price"; cout << setw(10) << right << fixed << setprecision(2) << price << endl; cout << setw(40) << left << "Units"; cout << setw(7) << right << units << endl; cout << setw(40) << left << "Total"; cout << setw(10) << right << fixed << setprecision(2) << total << endl; cout << setw(40) << left << "Discount"; cout << setw(7) << right << descPercentage << " %" << endl; cout << setw(50) << right << fixed << setprecision(2) << -amountDisc << endl; cout << setw(40) << left << "Total after discount"; cout << setw(10) << right << fixed << setprecision(2) << total << endl; cout << setw(40) << left << "VAT"; cout << setw(7) << right << VAT << " %" << endl; cout << setw(50) << right << fixed << setprecision(2) << amountVAT << endl; cout << setw(40) << left << "Final Price"; cout << setw(10) << right << fixed << setprecision(2) << final << endl; sale = true; cout << sale; } case 5: system ("CLS"); break; default: cout << "1. Client Data" << endl; cout << "2. Sale Data" << endl; cout << "3. Invoice" << endl; cout << "4. Totals" << endl; cout << "5. Restart" << endl; cout << "0. Exit" << endl; cout << "Option: "; cin >> option; cout << endl; } return 0; } int menu() { int option; int readMenu; cout << "1. Client Data" << endl; cout << "2. Sale Data" << endl; cout << "3. Invoice" << endl; cout << "4. Totals" << endl; cout << "5. Restart" << endl; cout << "0. Exit" << endl; cout << "Option: "; cin >> option; cout << endl; while (option <= -1 || option >= 6) { cout << "1. Client Data" << endl; cout << "2. Sale Data" << endl; cout << "3. Invoice" << endl; cout << "4. Totals" << endl; cout << "5. Restart" << endl; cout << "0. Exit" << endl; cout << "Option: "; cin >> option; cout << endl; } return option; } double cost(int descPercentage, double total, double final, double amountDisc, double amountVAT) { const int VAT = 21; const double DISCOUNT = 15; char discount; amountDisc = total * descPercentage / 100; total = total - amountDisc; amountVAT = total * VAT / 100; final = total + amountVAT; return final; }