unitprice_small = unitprice(diameter_small, price_small);
unitprice_large = unitprice(diameter_large, price_large);
is giving me problems
The compiler says : "unitprice has not been declared".....then when i declare it its says : "unitprice can not be used as a function"
This thing is crazy , I dont get it.
I copied this program out of a c++ book from college
Thanks
Code:
#include <iostream>
using namespace std;
int main()
{
int diameter_small, diameter_large, unitprice;
double price_small, unitprice_small;
double price_large, unitprice_large;
cout << "Welcome to the pizza consumer union.\n";
cout << "Enter diameter of a small pizza ( in inches): ";
cin >> diameter_small;
cout << "Enter the price of a small pizza: ";
cin >> price_small;
cout << "Enter diameter of a large pizza: (in inches)";
cin >> diameter_large;
cout <<"Enter the price of a large pizza: ";
cin>> price_large;
unitprice_small = unitprice(diameter_small, price_small);
unitprice_large = unitprice(diameter_large, price_large);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"small pizza:\n";
cout<<"diameter = " <<diameter_small<<"inches\n"
<<"Price = $ " <<price_small
<<" per square inch =$" << unitprice_small<<endl
<<"large pizza:\n";
cout<< "Diameter = " << diameter_large<< "inches\n";
cout<<"Price = " << price_large;
cout<< "per square inch = " << unitprice_large;
if (unitprice_large < unitprice_small)
cout << "The the large one is a better buy\n";
else
cout <<"The small one is better buy\n";
system("pause");
return 0;
}
double unitprice(int diameter, double price)
{
const double PI = 3.14159;
double radius, area;
radius = diameter/static_cast<double>(2);
area = PI * radius * radius;
return (price/area);
}


