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 a, b, and t, and outputs the number of dishes Bianca can prepare.
#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 ) );
}
Comments
Leave a comment