Answer to Question #239298 in C++ for HelloWorld

Question #239298

Bianca is preparing special dishes for her daughter’s birthday.

It takes her a minutes to prepare the first dish, and each following dish takes b minutes longer than the previous dish. She has t minutes to prepare the dishes.

For example, if the first dish takes a = 10 minutes and b = 5, then the second dish will take 15 minutes, the third dish will take 20 minutes, and so on.

If she has 80 minutes to prepare the dishes, then she can prepare four dishes because 10 + 15 + 20 + 25 = 70.

Write a program that prompts the user to enter the values of ab, and t, and outputs the number of dishes Bianca can prepare.


1
Expert's answer
2021-09-19T11:32:00-0400
#include <iostream>
# include<stdio.h>

using namespace std;

main()
{
	int a, b, t,i,Sum=0;
	int No_of_Dishes=0;
	cout<<"\n\tEnter a = "; cin>>a;
	cout<<"\n\tEnter b = "; cin>>b;
	cout<<"\n\tEnter t = "; cin>>t;
	Sum=0;
	for(i=a;Sum<=t;i=i+b)	
	{
		Sum = Sum+i;
		if(Sum<=t) No_of_Dishes=No_of_Dishes+1;
	}
	cout<<"\n\tNo. of Dishes = "<<No_of_Dishes;
	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

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS