Write a program to get the purchasing and selling price of a product and calculate its profit when 5 products are sold.
#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;
}
Comments
Leave a comment