Write a program that computes the total cost of a chocolate sale. The default cost per chocolate is $8,however, when a user buys more than 10 chocolates the shopkeeper can sell the chocolates at a discounted price that is less than $8 (only integer values). Define a function ComputeTotalCost that receives two arguments chocolatesSold and cost. The function should return the total cost back to the main function.
Calling:
If the number of chocolates bought is less than or equal to 10, the function receives only one argument—chocolatesSold. Otherwise, the function receives two arguments chocolatesSold and Cost. In the second case, the user(shopkeeper) inputs the Cost. The program should repeat until the user quits.
Lastly, print the number times ComputeTotalCost gets called before exiting the program.
Constraints/Hints:
All the variables and user inputs are non-negative integers.
This is my code, i was just wondering if i am on the right track and where to go from here because i am stuck.
#include <iostream>
usingnamespace std;
int ComputeTotalCost(int &, int &);
int ComputeTotalCost(int &);
int main()
{
int cost=8;
int chocolatesSold, total;
cout<<"How many chocolates did youo buy? ";
cin>>chocolatesSold
if(chocolatesSold<10)
{
computeTotalCost(chocolatesSold);
}
if(chocolatesSold>9)
{
computeTotalCost(chocolatesSold, cost);
}
return 0;
}
int ComputeTotalCost(int &val1, double &val2)
{
cout<<"How much is the discounted price? ";
cin>>cost;
return val1*cost;
}
int ComputeTotalCost(int &val1)
{
return val1*cost;
}