mercredi 28 février 2018

Loops, which to use, and how to stop it

my prompt is: Suppose that one credit hour for a course is $100 at a school and that rate increases 4.3% every year. In how many years will the course’s credit hour cost tripled?

The rewrote this simple code many times, but just can't seem to get it. I think i'm going about this the wrong way..

import java.util.Scanner;
public class MorenoJonathonCreditHourCostCalculator 
   {
 public static void main(String[] args)
    {

Scanner sc = new Scanner(System.in);


double cost = 100;
int years=0;
double sum=200;
double total;

    while (cost >= sum) {
        total = cost + 4.03;
        ++years;
    }


System.out.println("The tuition will double in " +years + " years ");
    }
}

Aucun commentaire:

Enregistrer un commentaire