My issue
First time asking for help, let me know if I’m doing this wrong.
I’ve designed what I believe to be an elegant solution, where I’m simply triggering a loop that will count how many trial lessons it will take to bring the (cost * (1 - discount * trial lessons taken)) down below the (budget - cost of trial lessons). Then I just compare the number of trial lessons with my budget to determine if I ended the loop because he ran out of money or because he was able to purchase it. It passes the example test case, but not the hidden test case. Can someone show me where I might be forgetting something? I’m sure there’s an edge case I haven’t considered.
My code
#include <iostream>
using namespace std;
int main() {
int tests;
cin >> tests;
while (tests--)
{
double D, C, B, i;
cin >> D >> C >> B;
for (i = 0; (B - i) < (C * (1 - ((D*i) / 100))) && i < B; i++);
if (i == B) cout << -1 << endl;
else cout << i << endl;
}
return 0;
}
Problem Link: International Gym Day Practice Coding Problem