The definition of unitprice does not do any input or output and so does
not use the library iostream.
In main we needed the using directive because cin and cout are defined in iostream and those definitions place cin and cout in the std namespace.
PROGRAM CODE:
#include <iostream>
double unitprice(double price, int quantity) {
return price / quantity;
}
int main() {
using namespace std; // Using directive to bring the std namespace into scope
double price;
int quantity;
cout << "Enter the price: ";
cin >> price;
cout << "Enter the quantity: ";
cin >> quantity;
double result = unitprice(price, quantity);
cout << "The unit price is: " << result << endl;
return 0;
}
OUTPUT OF THE PROGRAM CODE:
Enter the price: 100
Enter the quantity: 2000
The unit price is: 0.05