#include<iostream>
usingnamespace std;
void getInput(int& numOfDays, double& itemPrice);
double total(int& numOfDays, double& itemPrice);
void displayResults();
int main()
{
int numOfDays;
double itemPrice;
getInput(numOfDays, itemPrice);
total(numOfDays, itemPrice);
displayResults();
}
void getInput(int& numOfDays, double& itemPrice)
{
cout << "Please enter item price: $";
cin >> itemPrice;
while (itemPrice <= 0)
{
cout << "Invalid Input. Please enter a positive value: ";
cin >> itemPrice;
}
cout << "\nHow many days until the item is sold?: ";
cin >> numOfDays;
while (numOfDays <= 0)
{
cout << "Invalid Input. Please enter a positive value: ";
cin >> numOfDays;
}
}
double total(int& numOfDays, double& itemPrice)
{
double total;
if (numOfDays <= 7)
{
total = itemPrice + (itemPrice * 0.05);
return total;
}
else
{
total = itemPrice + (itemPrice * 0.10);
return total;
}
}
void displayResults()
{
cout << "\nThe total is: " << total << "\n" << endl;
}
So this program is supposed to calculate the price of an item, and return it back as the variable total of type int. but for some reason it gives me a weird output on total. And am i using call by reference correct? sorry, i am just learning. Please help out!