Advertisement
jbonanno

C++ Structure Example

Nov 17th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. // the struct product is declared.
  5. struct product
  6. {
  7.     char nameProduct[50];
  8.     char category[50];
  9.     int inventory;
  10.     float price;
  11. };
  12.  
  13. int main()
  14. {
  15.  
  16. // The user is asked to enter information about the product.
  17.     product s;
  18.     cout << "Enter information," << endl;
  19.     cout << "Enter the product name: ";
  20.     cin >> s.nameProduct;
  21.     cout << "Please enter the product category: ";
  22.     cin >> s.category;
  23.     cout << "Please enter the number of this item left in stock: ";
  24.     cin >> s.inventory;
  25.     cout << "Please enter the price of this item: ";
  26.     cin >> s.price;
  27.  
  28.  // The user's inputs are displayed.
  29.     cout << "Displaying Information," << endl;
  30.     cout << "Product name: " << s.nameProduct << endl;
  31.     cout << "Product Category: " << s.category << endl;
  32.     cout << "Number of items in stock: " << s.inventory << endl;
  33.     cout << "Price: " << s.price << endl;
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement