Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

c++ Problem4 Ingredient Adjuster 5 points A cookie recipe calls for the followin

ID: 3753073 • Letter: C

Question

c++

Problem4 Ingredient Adjuster 5 points A cookie recipe calls for the following ingredients: .5 cups of sugar .1 cup of butter 2.75 cups of flour The recipe produces 48 cookies with this amount of the ingredients. Write a program that asks the user how many cookies he or she wants to make, and then displays the number of cups of each ingredient needed for the specified number of cookies. Format your output nicely that all numbers and decimals align as shown in the example! Limit decimals to four digits -_ Ingredient Adjuster Number of cookies: 30 Cups of sugar needed 0.9375 Cups of butter needed: 0.6250 Cups of flour needed: 1.7187

Explanation / Answer

#include <iostream>

#include <iomanip>

using namespace std;

int main()

{

    float sugar, butter, flour, cookies;

    cout <<"Number of Cookies: "<<endl;

    cin>>cookies;

    sugar=(1.5*cookies)/48;// This will calculate the number of cups of sugar

    butter= (float) (1*cookies)/48; //This will calculate the number of cups of butter

    flour= (2.75*cookies)/48;//This will calculate the number of cups of flour

    std::cout<<"Cups of sugar needed: "<<std::fixed<<std::setprecision(4)<<sugar<<endl;

    std::cout<<"Cups of butter needed: "<<std::fixed<<std::setprecision(4)<<butter<<endl;

    std::cout<<"Cups of flour needed: "<<std::fixed<<std::setprecision(4)<<flour<<endl;

    return 0;

}

Note: setprecision(4) is used to limit the decimal to 4 digits.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote