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'm not sure how to call it correctly or how to pass the parameters. Please help?
Here's what I have so far:
Code:
#include <iostream>
using namespace std;
char pizzaType;
void getData(int length, int width, int price);
void getData(int diameter, int price);
double computeUnitCost(int diameter, int price);
double computeUnitCost(int length, int width, int price);
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')
int diameter;
int price;
void getData();
cout << "The price per square inch for this pizza is " << getData(diameter, price) << endl;
//return 0;
if (pizzaType == 's')
int squarePrice = getData(int& length, int& width, int& price);
cout << "The price per square inch for this pizza is " << getData << endl;
}
void 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 computeUnitCost(int&, int&);
}
void getData(int& diameter, int& price)
{
cout << "Enter in the diameter of the pizza in: " << endl;
cin >> diameter;
cout << "Enter in the the price of the pizza in: " << endl;
cin >> price;
}
double computeUnitCost(int diameter, int price)
{
int roundCost = diameter / price;
cout << "The price per square inch for this pizza is: " << roundCost << endl;
return roundCost; // not sure if i need to return this or if its the right way
}
double computeUnitCost(int length, int width, int price)
{
int squareCost = ((length * width))/ price;
cout << "The price per square inch for this pizza is: " << squareCost << endl;
return squareCost; // not sure if this is the right way to return it
}