Hi,
I need to write a n00b program that calculates the best deal customers can get when buying pizza. The premise is, although an extra large pizza may appear a better buy, you need to calculate the cost per sq inch of both round and rectangular pizzas to really know.
What I need to do:
-use function overloading
-write functions that pass by value and by reference
-use the SAME named function twice(for a total of 4 functions), call them getData and computeUnitCost
The first function gets all user input for round pizza, and must store the values it gets from the user where they can be accessed by other parts of the program(no global variables)length, width, price.
The 2nd function gets all user input for square pizza and the rest of the info like the first function.
The 3rd and 4th functions are computeUnitCost and do the computations. One takes the diameter and price as parameters, and returns the cost of 1 sq in of pizza. The other take the length and price and returns the cost. The function should be overloaded.
I need some help with how to call the functions and how to set up the overloading plz? :)
Here's what I have so far:
#include <iostream>
using namespace std;
char pizzaType;
double getData(int, int, int);
int main()
{
bool okay = true;
do {
cout << "Please enter in the type of pizza: " << endl;
cout << "r - a round pizza" << endl;
cout << "s - a square pizza" << endl;
cin >> pizzaType;
cin.ignore(80, '\n');
okay = (pizzaType == 'r' || pizzaType == 's');
cout << "\nYou entered an invalid pizza type!" << endl;
}while(!okay);
if (pizzaType == 'r')
double totalPrice = getData(length, width, price);
cout << "The price per square inch for this pizza is " << totalPrice << endl;
return 0;
}
double getData(int length, int width, int price)
{
cout << "Enter in the length of the pizza: " << endl;
cin >> length;
cout << "Enter in the width of the pizza: " << endl;
cin >> width;
cout << "Enter in the price of the pizza: " << endl;
cin >> price;
}
double getData(int diamter, int price)
{
cout << "Enter in the diameter of the pizza: " << endl;
cin >> diameter;
cout << "Enter in the the price of the pizza: " << endl;
cin >> price;
}
double computeUnitCost(diameter, price)
{
roundCost = diameter / price;
return roundCost;
cout << "The price per square inch for this pizza is: " << roundCost << endl;
}
double computeUnitCost(length, width, price)
{
squareCost = ((lenth * width))/ price;
return squareCost;
cout << "The price per square inch for this pizza is: " << squareCost << endl;
}