cs161AWinter2024/order.cpp

39 lines
1.1 KiB
C++

// Program to calculate cost of an order of pizzas
// from how many people, cost of a pizza, slices per person, number of slices in a pizza
// total cost = 1.25*(cost of a pizza * number of pizzas we need)
// number of pizzas we need = number of people * slices per person / slices in a pizza
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int numOfPeople;
int slicesPerPerson;
float slicesInPizza = 12;
float numberOfPizzas;
//slicesInPizza = 12
float costPerPizza;
float totalCost;
float tipPercent = 1.25;
cout << "Enter the number of people: " << endl;
cin >> numOfPeople;
cout << "Enter the number of slices per person: " << endl;
cin >> slicesPerPerson;
cout << "Cost of a pizza: " << endl;
cin >> costPerPizza;
numberOfPizzas = ceil(numOfPeople * slicesPerPerson / slicesInPizza);
//cout << "Testing: " << numberOfPizzas << endl;
totalCost = tipPercent*(numberOfPizzas * costPerPizza);
cout << "You bought: " << numberOfPizzas << " pizzas" << endl;
cout << "For a cost of: " << totalCost << " dollars" << endl;
return 0;
}