Using struct
B) Program Sample Run
Enter the data about the fruit.
Name: Apple
Color: green
Fat: 10
Sugar: 50
Carbohydrate: 100
Here are the details about the fruit.
The fruit's name is Apple.
Its color is green.
It contains 10 amount of fat, 50 amount of sugar, and 100 amount of carbohydrate.
#include <iostream>
struct Fruit
{
std::string name;
std::string color;
int fat;
int sugar;
int carbohydrate;
};
int main()
{
Fruit apple;
apple.name = "Apple";
apple.color = "green";
apple.fat = 10;
apple.sugar = 50;
apple.carbohydrate = 100;
std::cout << "Here are the details about the fruit.\nThe fruit's name is " << apple.name << ".\n"
<< "Its color is " << apple.color << ".\n"
<< "It contains "<<apple.fat<<" amount of fat, "<<apple.sugar<<" amount of sugar, and "<<apple.carbohydrate<<" amount of carbohydrate.\n";
system("pause");
return 0;
}
Comments
Leave a comment