Please tell me the solution. Why is this not working | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Please tell me the solution. Why is this not working

You take a loan from a friend and need to calculate how much you will owe him after 6 months. You are going to pay him back 10% of the remaining loan amount each month. Create a program that takes the loan amount as input, calculates and outputs the remaining amount after 6 months. Sample Input: 20000 Sample Output: 10628 My code: https://code.sololearn.com/c6AEUVZS08Ba/?ref=app

15th Feb 2021, 9:41 AM
<Sai></Mishra>
<Sai></Mishra> - avatar
6 Answers
+ 6
On line 11, change `int` to `double`. Also, change 100 to 100.0 (you can also change 10 to 10.0) to get the answer as a double instead of an `int`. How would this help? On the surface it might seem that it won't affect the answer, but try adding the following line to the top of the loop body to see the difference in the 'amount's in each iteration `System.out.println((amount - amount * 10/100) + ", " + (amount - amount * 10/100.0));`
15th Feb 2021, 10:04 AM
XXX
XXX - avatar
+ 2
Please show your attempt.
15th Feb 2021, 9:46 AM
XXX
XXX - avatar
15th Feb 2021, 9:50 AM
<Sai></Mishra>
<Sai></Mishra> - avatar
+ 1
My attempt
15th Feb 2021, 9:50 AM
<Sai></Mishra>
<Sai></Mishra> - avatar
+ 1
XXX Thanks a lot
15th Feb 2021, 11:37 AM
<Sai></Mishra>
<Sai></Mishra> - avatar
+ 1
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); for(int i=0;i<6;i++){ amount -= (amount * 0.1); } System.out.println(amount); } } This helps you maybe
17th Feb 2021, 3:11 AM
❤️😍Prerana😍❤️
❤️😍Prerana😍❤️ - avatar