A simple but unsolved problem with ACMP. C++
The deposit in the bank is X rubles. Every year it increases by P percent, after which the fractional part of the kopecks is discarded.
It is necessary to determine: after how many years the contribution will be at least Y rubles.
Input data Input file INPUT.TXT contains three natural numbers: X, P, and Y (X, Y ≤ 1000, P ≤ 100).
Output data to the output file OUTPUT.TXT output an integer- the answer to the task.
Solution code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int x, p, y, cnt = 0;
cin >> x >> p >> y;
while (x < y)
{
x *= 1 + p / 100.0;
cnt++;
}
cout << cnt;
}
The decision did not count. Floating point problem? in the line x *= 1 + p / 100.0
there are no errors with the casts for sure (by 99%) I checked. What could be the problem?
0
1 answers
The floating point is not needed here at all. Work in kopecks.
int x, p, y, cnt = 0;
cin >> x >> p >> y;
x = x * 100;
y = y * 100;
p = p + 100;
while (x < y)
{
x = (x * p) / 100;
cnt++;
}
2
Author: MBo, 2020-07-07 02:13:07