BlackWolfy

Calculate total price of products (Using struct)

Feb 15th, 2023
1,283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     struct product {
  6.         long int barcode;
  7.         string name;
  8.         float weight;
  9.         float price;
  10.         int quantity;
  11.     };
  12.     int n;
  13.     product prod[50];
  14.     product* q;
  15.     q = prod;
  16.     float total=0;
  17.     cout << "Enter a number of products: "<<endl;
  18.     cin >> n;
  19.     cout << "Product info: " << endl;
  20.     for (int i = 0; i < n; i++) { //loop for inputting product info
  21.         cout << "Product number "<<i+1<<": "<<endl;
  22.         cout << "Enter barcode: "<<endl;
  23.         cin >> q->barcode;
  24.         cout << "Enter name: " << endl;
  25.         cin >> q->name;
  26.         cout << "Enter weight: " << endl;
  27.         cin >> q->weight;
  28.         cout << "Enter price: " << endl;
  29.         cin >> q->price;
  30.         cout << "Enter quantity: " << endl;
  31.         cin >> q->quantity;
  32.         total = total+ (q->price*q->quantity);
  33.         q++;
  34.     }
  35.     cout << "The "<<n<<" types of products cost a total of "<<total;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment