Okay for the life of me I cannot get the right output for my program. I need to get the total number of pennies in dollar amount for the output of Total Pay. This is my program. The directions are:
Write a program that calculates the amount a person would
earn over a period of time if his or her salary is one penny the first day,
two pennies the second day, and continues to double each day. The program should then show the total pay at the
end of the period. The output should be displayed in a dollar amount, not the number
of pennies. Do not accept a number less than 1 for the number of days worked.
import java.util.Scanner; import java.text.DecimalFormat; public class PenniesForPay { public static void main(String[] args) { int numDays; int pennies = 1; int day = 1; double totalSalary = 0.01; Scanner keyboard = new Scanner(System.in); DecimalFormat formatter = new DecimalFormat("#,###.##"); System.out.print("Please enter the number of days worked: "); numDays = keyboard.nextInt(); while (numDays < 1) { System.out.print("Enter the number of days worked: "); numDays = keyboard.nextInt(); } System.out.println(" "); System.out.println("Day " + " Pennies(earned)"); System.out.println("------------------------"); while (numDays > 0) { System.out.println(day + " = " + " " + formatter.format(pennies)); pennies *= 2; totalSalary += pennies / 100; day++; numDays--; } System.out.println(" "); System.out.println("Total pay: $" + formatter.format(totalSalary)); } }
--- Update ---
totalSalary should be total number of pennies / 100....However its not picking up only day 30 of pennies which is 536,870,912 pennies and then dividing it?