Answer to Question #247962 in C++ for jak

Question #247962

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-10-07T03:04:30-0400
#include <iostream>
#include <cmath>
using namespace std;


int main()
{
   double a, d, t, c;
   cout << "Enter time spent to prepare the first dish: ";   
   cin >> a;
   cout << "Enter amount of time required to prepare the second dish: "; 
   cin >> d;
   cout << "Enter time available to prepare the dish: "; 
   cin >> t;
   c = 2 * a - d;
   cout << "Number of dishes  : " << (int)( (-c + sqrt( c * c + 8 * d * t ) ) / ( 2.0 * d ) );
}

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