/*Define a structure that represents Fruit with properties of fruit name, fruit type, fruit color.
Write a program that accepts data of four fruits and displays the results. */
#include <iostream>
using namespace std;
//Defining a struct
struct Fruit
{
char name[50], type[50], color[50];
int roll;
} f[4];
int main()
{
cout << "Enter Fruit and fruit properties: " << endl;
// accepts data of four fruits
for(int i = 0; i < 4; ++i)
{
f[i].roll = i+1;
cout << "For roll number" << f[i].roll << "," << endl;
cout << "Enter fruit name: ";
cin >> f[i].name;
cout << "Enter fruit type: ";
cin >> f[i].type;
cout << "Enter fruit color: ";
cin >> f[i].color;
cout << endl;
}
cout << "Displays the results: " << endl;
//Displays the results
for(int i = 0; i < 4; ++i)
{
cout << "\nRoll number: " << i+1 << endl;
cout << "Fruit Name: " << f[i].name << endl;
cout << "Fruit type: " << f[i].type << endl;
cout << "Fruit color: " << f[i].color << endl;
}
return 0;
}
Comments
Leave a comment