Answer to Question #298090 in C++ for Kelly

Question #298090

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.

1
Expert's answer
2022-02-15T08:15:07-0500
#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;
}

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