Trying to wrap up my invoice program. I'm trying to get my customerInvoice function to properly display. However whenever I try to use it, I get an error. For some reason this function is having a difficult time displaying, and I'm not sure what the complication is. I can enter my values in just fine, none of the other variables are having a hang-up, I'm just getting a bit stalled on this part as its not properly displaying the message inside the customerInvoice function.
I also want my invoice to recognize the senior discount: if the customers age is over 60, then they get the 0.05 multiplier discount on their purchase.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
const float flatTaxRate = 0.08;
const float seniorDiscountRate = 0.05;
int getIntValue (string toInput){
cout << "Please enter " << toInput <<": ";
int value;
cin >> value;
return value;
}
string choiceOfItem(int choice) {
return choice == 1 ? "Bread" :
choice == 2 ? "Milk" :
choice == 3 ? "Soap" :
choice == 4 ? "Eggs" :
choice == 5 ? "Deodorant" :
choice == 6 ? "Juice" :
choice == 7 ? "Chips" :
choice == 8 ? "Forks" :
choice == 9 ? "Spoons" :
choice == 10 ? "Cups" :
"Invalid Item: Select Again";
}
int getIntInputValues (string toInput){
cout << "Please enter " << toInput <<": ";
int value;
cin >> value;
return value;
}
double getDoubleInputValues (string toInput){
cout << "Please enter " << toInput <<": ";
double value;
cin >> value;
return value;
}
bool customerAge(int age){
const int seniorCustomer = 60;
return age >= seniorCustomer;
}
void customerInvoice(int choice, double price, int age)
{
cout << "-----------------------------------\n";
cout << "\n" << "Invoice" << "\n";
//can use \n as a tab
if(seniorCustomer(age))
{
price -= price * seniorDiscountRate;
}
cout << choiceOfItem(choice) <<":" << "\n" <<"$"<< price << endl;
cout << "Tax:" << "\n" <<"$"<< price * flatTaxRate << endl;
cout << "Discount:" << "\n" <<"$"<< "-" << price * seniorDiscountRate << endl;
cout << "Total:" << "\n"<< "$" << price + (price * flatTaxRate) << endl;
cout << "-----------------------------------\n";
}
int main()
{
const int MIN_VALID = 1;
const int MAX_VALID = 10;
cout << "What would you like to buy?" << endl;
for (int choice = MIN_VALID; choice <=MAX_VALID; ++choice)
{
cout << choice << ". " << choiceOfItem(choice)<< endl;
}
cout << endl;
int choice = getIntValue("your choice");
while (choice < MIN_VALID || choice > MAX_VALID)
{
cout << "Sorry, " << choice << " wasn't a valid choice" << endl;
cout << "Please try again:" << endl;
choice = getIntValue("your choice");
}
double price = getDoubleInputValues("price");
int age = getIntInputValues("age");
bool seniorCustomer;
cout << " " << endl;
customerInvoice;
cout << choiceOfItem(choice) << endl;
cout << price << endl;
cout << age << endl;
cout << seniorCustomer;
return 0;
}