#need help with code

5 messages · Page 1 of 1 (latest)

midnight hawk
#

#include <iostream>
#include <fstream>

using namespace std;

class Sandwich {
public:
string name;
int price;
};

class Extra {
public:
string name;
int price;
};

class Drink {
public:
string name;
int price;
};

class Shop {
public:
Sandwich sandwich;
Extra extra;
Drink drink;
string username, password;
bool state;
int counter;

void showWelcomeMessage() {
    cout << "Welcome to the Sandwich Shop!" << endl;
}

void buyNewItem() {
    Sandwich newSandwich[20];

    newSandwich[counter].name = sandwich.name;
    newSandwich[counter].price = sandwich.price;

    Extra newExtra[20];

    newExtra[counter].name = extra.name;
    newExtra[counter].price = extra.price;

    Drink newDrink[20];

    newDrink[counter].name = drink.name;
    newDrink[counter].price = drink.price;

    cout << "You have purchased:" << endl;
    cout << "Sandwich: " << newSandwich[counter].name << " - Price: " << newSandwich[counter].price << "EGP" << endl;
    cout << "Extra: " << newExtra[counter].name << " - Price: " << newExtra[counter].price << "EGP" << endl;
    cout << "Drink: " << newDrink[counter].name << " - Price: " << newDrink[counter].price << "EGP" << endl;
    counter++;
}
jagged hedgeBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

midnight hawk
#

int main() {
string sandwiches[] = {"Chicken Shawarma", "Beef Shawarma", "Chicken Burger", "Beef Burger", "Sausage"};
float sandwichPrices[] = {25, 35, 12, 16, 10};
string extras[] = {"Extra Fries", "Extra Cheese", "Extra Mayo", "None"};
float extraPrices[] = {5, 8, 4, 0};
string drinks[] = {"Pepsi – Can", "Pepsi – Bottle", "Juice", "None"};
float drinkPrices[] = {10, 15, 8, 0};
bool state;

int selectedSandwichIndex, selectedExtraIndex, selectedDrinkIndex;
Shop myApp;

myApp.showWelcomeMessage();

state = myApp.login();

while (state) {
    myApp.showItemsWithPrices("Sandwiches", sandwiches, sandwichPrices, 5);
    selectedSandwichIndex = myApp.getUserInput("Select Sandwich: ");

    myApp.showItemsWithPrices("Extras", extras, extraPrices, 4);
    selectedExtraIndex = myApp.getUserInput("Select Extra: ");

    myApp.showItemsWithPrices("Drinks", drinks, drinkPrices, 4);
    selectedDrinkIndex = myApp.getUserInput("Select Drink: ");

    myApp.sandwich.name = sandwiches[selectedSandwichIndex - 1];
    myApp.sandwich.price = sandwichPrices[selectedSandwichIndex - 1];

    myApp.extra.name = extras[selectedExtraIndex - 1];
    myApp.extra.price = extraPrices[selectedExtraIndex - 1];

    myApp.drink.name = drinks[selectedDrinkIndex - 1];
    myApp.drink.price = drinkPrices[selectedDrinkIndex - 1];

    myApp.buyNewItem();

    cout << "Buy Another Item? [1=Yes - 0=No]: ";
    cin >> state;
}

if (myApp.calculateGrandTotal(1, 1, 1) > 0) {
    myApp.saveInvoiceDetailsAsTextFile();
    myApp.saveInvoiceDetailsAsCSVFile();
}
else {
    cout << "Invalid username or password" << endl;
}

return 0;

}

#

in this if (myApp.calculateGrandTotal(1, 1, 1) > 0) {
myApp.saveInvoiceDetailsAsTextFile();
myApp.saveInvoiceDetailsAsCSVFile();
}
else {
cout << "Invalid username or password" << endl;
}
i dont want to use the (1,1,1)