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 ingredients. Write a program that asks the user how many cookies they want to make and then displays the number of cups of each ingredient needed for the specified number of cookies in the following format: You need 5 cups of sugar, 3 cups of butter, and 7 cups of flour. Note: Don’t worry about formatting the numbers in the output.

Respuesta :

Answer:

This program is written using c++ programming language

Comments are used to explain difficult lines

See attachment for .cpp source files

Program starts here

#include<iostream>

using namespace std;

int main()

{

// Calculate number of ingredient that makes up 48 cookies

float num_sugar = 1.5/48;

float num_butter =1.0/48;

float num_flour = 2.75/48;

//Declare integer variable to get number of cookies from user

int n;

// Prompt user for number of cookies needed

cout<<"Enter number of cookies: ";

cin>>n;

// Calculate equivalent amount of ingredient

num_sugar *= n;

num_butter *= n;

num_flour *= n;

// Display Result

cout<<"You need "<<num_sugar<<" cups of sugar, "<<num_butter<<" cups of butter, and "<<num_flour<<" cups of flour.";

return 0;

}

//End of Program

Ver imagen MrRoyal