A cookie recipe calls for the following ingredients 15 cups

A cookie recipe calls for the following ingredients:

• 1.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

Solution

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
   int cookies;
   double sugar,butter,flour;
  
   cout<<\"How many cookies you want to make?\";
   cin>>cookies;
  
   sugar = 1.5/48 * cookies;
  
   flour = double(1)/48 * cookies;
  
   butter = 2.75/48 * cookies;
   cout<<fixed<<setprecision(2); //set precision of 2 decimal places
  
   cout<<\"\ For \"<<cookies<<\" cookies following ingredients are required\";
  
   cout<<\"\ \"<<sugar<<\" cups of sugar\";
  
   cout<<\"\ \"<<flour<<\" cups of flour\";
      
   cout<<\"\ \"<<butter<<\" cups of butter\";
  
   return 0;
}

output:

A cookie recipe calls for the following ingredients: • 1.5 cups of sugar • 1 cup of butter • 2.75 cups of flour The recipe produces 48 cookies with this amount

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site