Question
I have this code that I need to add the customer name to each order but not each sneaker I need help. I have this
I have this code that I need to add the customer name to each order but not each sneaker I need help. I have this code so far, just need to add the customer name to each order/ bill but not sneaker.
code:
#include
#include
#include
#include
using namespace std;
// print the receipt
void printReciept(double sizes[], string name[], double cost[], int count);
// get the total cost
double getTotal(double cost[], int count);
double getTax(double total, double percent);//to calculate the cost
double getCost();//to accept the cost and check for validation
double getsize(); //to accept the size and check for validation
int main(int argc, char** argv) {
double sizes[100];
string name[100];
double cost[100];
char ch;
int count = 0, i, j;
while (1) {
cout << "How many sneakers you want to enter? ";
cin >> count;
for (j = 0; j < count; j++) {
cout << " For sneakers " << (j + 1) << " ... ";
// get the size of the sneaker
sizes[j] = getsize();
std::cin.ignore(std::numeric_limits
// get the name of the sneaker
cout << " Enter name: ";
getline(cin, name[j]);
// get the cost of the sneaker
cost[j] = getCost();
}
printReciept(sizes, name, cost, j);
cout << " Do you have any new order (y/n) : ";
cin >> ch;
if (ch == 'n' or ch == 'N') // 'y' should be changed to 'n' because the loop must end when user doesn't need to enter new order
break;
}
return 0;
}
// print the reciept
void printReciept(double sizes[], string name[], double cost[], int count) {
int i;
cout << "===========RECEIPT============= ";
for (i = 0; i < count; i++) {
cout << "Sneaker " << (i + 1) << " ..." << endl;
cout << "Name : " << name[i] << endl;
cout << "Size : " << sizes[i] << endl;
cout << "Cost : " << cost[i] << endl << endl;
}
double tot = getTotal(cost, count);
double tax = getTax(tot, 8.25);
cout << " Cost : " << tot;
cout << " Tax 8.25% :" << tax;
cout << " Total Cost : " << tot + tax;
cout << " =============End============== ";
}
// get the total cost
double getTotal(double cost[], int count) {
double total = 0.0;
int i;
for (i = 0; i < count; i++)
total += cost[i];
return total;
}
//to get the tax amount
double getTax(double total, double percent) {
return (total * (percent / 100));
}
//to get the cost from user
double getCost() {
double cost;
do {
cout << " Enter cost: ";
cin >> cost;
if (cost < 1) { // if user enter negative value display the invalid message
cout << " Please enter the valid cost...";
}
} while (cost <= 0);//perform the loop until the valid input
return (cost);
}
double getsize() {
double s;
cout << " Enter size: ";
cin >> s;
while(cin.fail() || (s < 1) || (s > 13))
{// if user enter value<1 and>13 or user enters anything other than integers display the invalid message
std::cin.clear(); // back in 'normal' operation mode
std::cin.ignore(std::numeric_limits
cout << " Please enter the valid size...";
cout << " Enter size: ";
cin >> s;
}
return (s);
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started