# whats wrong with this program

.
.
I copied this program out of a book. the problem revolves around the word:

unitprice

Its here on this part of the program that the problem comes up

unitprice_small = unitprice(diameter_small, price_small);
unitprice_large = unitprice(diameter_large, price_large);

The compiler is saying that the word..unitprice is not declared.....then when i do declare it, it says its not allowed to be declared.......

I cant figure this out, its crazy

thanks

#include
using namespace std:
int main()
{
int diameter_small, diameter_large;
double price_small, unitprice_small;
double price_large, unitprice_large;

cout << "Welcome to the pizza consumer union.
";
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:
";
cout<<"diameter = " <<diameter_small<<"inches
"
<<"Price = \$ " <<price_small
<<" per square inch =\$" << unitprice_small<<endl
<<"large pizza:
";
cout<< "Diameter = " << diameter_large<< "inches
";
cout<<"Price = " << price_large;
cout<< "per square inch = " << unitprice_large;
if (unitprice_large < unitprice_small)
cout << "The the large one is a better buy
";
else
cout <<"The small one is better buy
";
system("pause");
return 0;

}

double unitprice(int diameter, double price)
{
const double PI = 3.14159;

return (price/area);
}

• : .
: .
: I copied this program out of a book. the problem revolves around the
: word:
:
:
: unitprice
:
:
: Its here on this part of the program that the problem comes up
:
: unitprice_small = unitprice(diameter_small, price_small);
: unitprice_large = unitprice(diameter_large, price_large);
:
: The compiler is saying that the word..unitprice is not
: declared.....then when i do declare it, it says its not allowed to
: be declared.......
:
: I cant figure this out, its crazy
:
: thanks
:
:
:
: #include
: using namespace std:
: int main()
: {
: int diameter_small, diameter_large;
: double price_small, unitprice_small;
: double price_large, unitprice_large;
:
:
: cout << "Welcome to the pizza consumer union.
";
: 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:
";
: cout<<"diameter = " <<diameter_small<<"inches
"
: <<"Price = \$ " <<price_small
: <<" per square inch =\$" << unitprice_small<<endl
: <<"large pizza:
";
: cout<< "Diameter = " << diameter_large<< "inches
";
: cout<<"Price = " << price_large;
: cout<< "per square inch = " << unitprice_large;
: if (unitprice_large < unitprice_small)
: cout << "The the large one is a better buy
";
: else
: cout <<"The small one is better buy
";
: system("pause");
: return 0;
:
: }
:
: double unitprice(int diameter, double price)
: {
: const double PI = 3.14159;
:
: return (price/area);
: }
:
Why ask this at a Basic language board, while the language this program is written in is C?

• You need to [b]foward declare[/b] the function (or define it above main()).

To foward declare, just declare it before it's first use (i.e., above main()):
[code]
double unitprice(int diameter, double price);
[/code]

Remember that in C++, [b]everything must be defined before they are used[/b]. Your original code uses this routine without it ever being defined.

Either move your function above main(), or foward declare it.

---------

I do have to also ask why put this in this forum though o.0?