Returning A Value From a Seperate Function
If I had the program:
Code:
#include <iostream>
using namespace std;
void getItemPrice()
{
int price;
// making sure cost is not negative
do
{
cout << "Enter cost of item (in cents) :" << endl;
cin >> price;
} while (price <= 0);
// making sure cost is a multiple of 5
while ((price%5)!=0)
{
cout << "Price of item must be multiple of 5 cents." << endl;
cout << "Enter cost of item (in cents) :" << endl;
cin >> price;
// again making sure cost is not negative
while (price <= 0)
{
cout << "Enter cost of item (in cents) :" << endl;
cin >> price;
}
}
return price;
}
int main();
{
int price;
price = getItemPrice();
}
I compile it and get the a warning saying
In function 'void getItemPrice()':
return-statement with a value, in function declared with a void return
type
I'm just wondering why I am unable to return the value of price from my getItemPrice function back to the main function. I know the series of commands inside getItemPrice work because I copied and pasted it from the previous assignment that we are building off of.
Thanks