Question

A cookie recipe calls for the following ingredients: • 1.5 cups of sugar • 1 cup...

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

Homework Answers

Answer #1

#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<<"\nFor "<<cookies<<" cookies following ingredients are required";
  
   cout<<"\n"<<sugar<<" cups of sugar";
  
   cout<<"\n"<<flour<<" cups of flour";
      
   cout<<"\n"<<butter<<" cups of butter";
  
   return 0;
}

output:

How many cookies you want to make?96
For 96 cookies following ingredients are required
3.00 cups of sugar
2.00 cups of flour
5.50 cups of butter
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT