jbonanno icon

C++ Structure Example

jbonanno | PRO | 11/17/17 04:40:47 PM UTC | 0 ⭐ | 314 👁️ | Never ⏰ | []
C++ |

950 B

|

None

|

0 👍

/

0 👎

#include <iostream>
using namespace std;
 
// the struct product is declared.
struct product
{
    char nameProduct[50];
    char category[50];
    int inventory;
    float price;
};
 
int main()
{
 
// The user is asked to enter information about the product.
    product s;
    cout << "Enter information," << endl;
    cout << "Enter the product name: ";
    cin >> s.nameProduct;
    cout << "Please enter the product category: ";
    cin >> s.category;
    cout << "Please enter the number of this item left in stock: ";
    cin >> s.inventory;
    cout << "Please enter the price of this item: ";
    cin >> s.price;
 
 // The user's inputs are displayed.
    cout << "Displaying Information," << endl;
    cout << "Product name: " << s.nameProduct << endl;
    cout << "Product Category: " << s.category << endl;
    cout << "Number of items in stock: " << s.inventory << endl;
    cout << "Price: " << s.price << endl;
    return 0;
}

Comments