Question: There is something wrong when my input has break inside. Here is the problem and the question. Write a simple C++ program to calculate the

There is something wrong when my input has break inside. Here is the problem and the question.

Write a simple C++ program to calculate the profit/loss of N products based on their purchase costs, selling prices, and monthly sales. The program should:

Read the number of products N.

Use arrays of length N to store the following: the product names the number of purchases of each product the number of sales made for each product their purchase cost their selling prices the profit or loss incurred from each product Calculate the product profit or loss percentage based on the purchase cost and the sales made: = ( / ) * 100 where, = - = * = *

Also calculate the net profit or loss percentage based on the net profit/loss and the net purchase cost.

Keep track of the product profit/loss based on the three conditions:

If the profit/loss percentage is greater than 0 then mark the product sales as PROFIT.

If the profit/loss percentage is equal to 0 then mark the product sales as BREAK-EVEN.

If the profit/loss percentage is less than 0 then mark the product sales as LOSS.

Sort the products in descending order based on the profit/loss percentage of each product, starting with the most profitable product to the least. MSc CDA Take Home Assignment Pre-Application September 2021

For each product, print (in a tabular format): the product name, the number of purchases, the number of sales, the purchase cost, the selling price, the total purchase cost, the total sales, the overall profit/loss percentage, and the sales indicators.

At the end, print the net purchase cost, the net sales, and the net profit/loss percentage and the profit/loss indicator.

You do not need to worry about having exactly two decimal points and other fancy number formatting

Here is the code

#include using namespace std;

struct product {

string product_name; int no_of_purchase; int no_of_sales; float purchase_cost; float selling_price; float profit_loss; float percent_profit_loss; string product_sales; };

bool Compare(product P1,product P2) {

return P1.percent_profit_loss>P2.percent_profit_loss; } int main() {

int n; cout<<"Enter number of product:"; cin>>n;

product Products[n];

for(int i=0;i>Products[i].product_name; cout<<"Enter number of purchase: "; cin>>Products[i].no_of_purchase; cout<<"Enter number of sales: "; cin>>Products[i].no_of_sales; cout<<"Enter Purchase cost: "; cin>>Products[i].purchase_cost; cout<<"Enter selling price: "; cin>>Products[i].selling_price;

Products[i].profit_loss = (Products[i].selling_price)*(Products[i].no_of_sales) - (Products[i].purchase_cost) * (Products[i].no_of_purchase);

Products[i].percent_profit_loss = (Products[i].profit_loss/((Products[i].purchase_cost) * (Products[i].no_of_purchase)))*100;

if(Products[i].percent_profit_loss < 0) { Products[i].product_sales = "LOSS"; } else if(Products[i].percent_profit_loss == 0) { Products[i].product_sales = "BREAK-EVEN"; } else { Products[i].product_sales = "PROFIT"; }

}

sort(Products, Products+n, Compare); cout<<"Names"<

for(int i=0;i

float total_purchase_cost = 0, total_sales_cost = 0, net_percent_profit_loss; string net_profit_loss_indicator;

for(int i=0;i

if(net_percent_profit_loss < 0) { net_profit_loss_indicator = "LOSS"; } else if(net_percent_profit_loss == 0) { net_profit_loss_indicator = "BREAK-EVEN"; } else { net_profit_loss_indicator = "PROFIT"; }

}

cout<<"Total purchase cost = "<

However when I type input "TV Stand" when I run it, the program can't work because of the break in "TV Stand". How should I change the code in order to allow the system to enter break when running program?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!