Heya this is the issue that I am solving:
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.
Here is my code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include <iostream>
using namespace std;
int main() {
// Write your main here
int Initial_Dish_Time; //Initial time required to make a dish.
int Incremental_Dish_Time; //The ratio by which the time increases.
int Added_Dish_Time; //An increasing value which increases by the incremental dish time.
int Time_Limit;
int Possible_Dishes = 0;
cout << "Enter the time used to create the first dish: ";
cin >> Initial_Dish_Time;
cout << "Enter the extra time needed to create the second dish: ";
cin >> Incremental_Dish_Time;
cout << "Enter the available time: ";
cin >> Time_Limit;
Added_Dish_Time = Incremental_Dish_Time;
for(int i = Initial_Dish_Time; i <= Time_Limit; i += Added_Dish_Time + Initial_Dish_Time)
{
Added_Dish_Time += Incremental_Dish_Time;
if(i <= Time_Limit)
Possible_Dishes++;
}
cout << "Possible number of dishes in given time: " << Possible_Dishes;
return 0;
}
|
The issue I have is that is the math seems to fall short by 1 on certain inputs.
Example:
2
5
9999999
Expected Result: 2000
Current Result: 1999
I don't quote know what I am looking for here to solve this issue.