Answer to Question #157996 in C++ for hifza

Question #157996

Write a program to get the purchasing and selling price of a product and calculate its profit when 5 products are sold.


1
Expert's answer
2021-01-24T16:38:22-0500
#include <iostream>
#include <iomanip>
using namespace std;
int main () {
    // product amount
    int n;
    float selling_price[n];
    float purchasing_price[n];
    cout << "enter number of products: "; cin >> n;
    for (int i = 0; i < n; i++) {
        cout << "Enter the " << i + 1 << " - product purchasing price: ";
        cin >> purchasing_price[i];
        cout << "Enter the " << i + 1 << " - product selling price: ";
        cin >> selling_price[i];
    }
    cout << "\nInformation about product:\n";
    cout << setw(10) << "product" << setw(20) << "purchasing_price" << setw(20) << "selling_price\n";
    for (int i = 0; i < n; i++) {
        cout << setw(10) << i + 1 << setw(20) << purchasing_price[i] << setw(20) << selling_price[i] << endl;
    }
    float profit = 0;
    for (int i = 0; i < 5; i++) {
        profit += (selling_price[i] - purchasing_price[i]);
    }
    cout << "profit the first 5 products: " << profit;
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS