Answer to Question #159231 in C++ for Ali

Question #159231

Write a C++ program to create user_defined datatype as Fruits having attributes as Name, color and price


1
Expert's answer
2021-01-28T04:28:35-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog