工资柜台的最终工资没有增加?

Final salary does not increase in salary counter?

所以我为这个实验室提示写了一个工资计算器:

编写一个显示教师工资表的程序。输入是起薪、增长百分比和时间表中的年数。输出时间表中的每一行都应包含年份编号和当年的薪水。

import java.util.Scanner;

public class Lab2_10
{

   public static void main (String[] args)
   {
   // Get values
   Scanner scanner = new Scanner(System.in);
   System.out.print("Enter the base first year salary: ");
   int first = scanner.nextInt(); 
   System.out.println("Enter the percentage increase: ");
   int percent = scanner.nextInt();
   System.out.println("Enter the number of years in the schedule: ");
   int years = scanner.nextInt();

   // Calculate salary for each year
   int total = first;
   int i = 1;
   int increment = percent / total * 100;
   while (i <= years && years <= 25)
   {
      increment = percent / total * 100;
      total += increment;
      System.out.println(total + " " + i);
      i++;
   }

   }
}

这就是我目前所拥有的。但是,增量线似乎不起作用。当我输入 40,000 作为基本工资并在 20 年内增长 5% 时,它 returns 这个。

40000 1
40000 2
40000 3
40000 4
40000 5
40000 6
40000 7
40000 8
40000 9
40000 10
40000 11
40000 12
40000 13
40000 14
40000 15
40000 16
40000 17
40000 18
40000 19
40000 20

我知道年份在递增,但薪水保持不变。我想知道这是循环问题还是声明问题?我真的不知道如何解决它。

你的%计算逻辑不正确

int increment = percent / total * 100;

改为

int increment = total * percent / 100.0; // note 100.0

这里有 2 件事。

  1. Simple math
  2. Integer division