Write a C++ program to create user_defined datatype as Fruits having attributes as Name, color and price
#include <iostream>
#include <string>
using namespace std;
struct Fruits
{
string Name;
string color;
float price;
};
int main()
{
Fruits abc[10];
for (int i = 0; i < 10; i++)
{
cout << "Enter the name of the fruit: ";
cin >> abc[i].Name;
cout << "Enter the color of the fruit: ";
cin >> abc[i].color;
cout << "Enter the price of the fruit: $";
cin >> abc[i].price;
}
for (int i = 0; i < 10; i++)
{
cout << "The name of the fruit: " << abc[i].Name << endl
<<"The color of the fruit: "<<abc[i].color<<endl
<<"The price of fruit: $" << abc[i].price << endl;
}
return 0;
}
Comments
Leave a comment