+ 1

pls help

import java.util.Scanner; public class CompoundInterest { public static void main(String[] args) { Scanner inp=new Scanner(System.in); double p=inp.nextDouble(); double r=inp.nextDouble(); double t=inp.nextDouble(); while(t>0) { double i=(p*r)/100; double tt=1; System.out.println("Interest for "+tt+" years : "+i); p+=i; tt++; t--; } } } //why year is resulting 1 always

6th Jan 2018, 10:00 AM
Ahmer Siddiqui
Ahmer Siddiqui - avatar
1 Antwort
+ 13
The value of tt must be initialized before starting the loop. Otherwise it will be re-initialized with 1 again and again. https://code.sololearn.com/cGU1s4sgU0lg/?ref=app
6th Jan 2018, 10:09 AM
Shamima Yasmin
Shamima Yasmin - avatar