invoiceApp help with coding
I am simply trying to calculate the number of invoices: the average invoice: and the average discount:, the code i have been working with is at the bottom. I appreciate any help with this.
import java.text.DecimalFormat;
import java.util.Scanner;
public class InvoiceApp
{
public static void main(String[] args)
{
// welcome the user to the program
System.out.println("Welcome to the Invoice Total Calculator");
System.out.println(); // print a blank line
// create a Scanner object named sc
Scanner sc = new Scanner(System.in);
// perform invoice calculations until choice isn't equal to "y" or "Y"
String choice = "y";
while (choice.equalsIgnoreCase("y")) {
while (!choice.equalsIgnoreCase("n"))
{
// get the invoice subtotal from the user
System.out.print ("Enter subtotal: ");
double subtotal = sc.nextDouble();
// calculate the discount amount and total
double discountPercent= 0.0;
if (subtotal >= 200) {
discountPercent = .25;
}
else if (subtotal >= 100) {
discountPercent = .1;
}
else {
discountPercent = 0.0;
}
double discountAmount = subtotal * discountPercent;
double total = subtotal - discountAmount;
// display the discount amount and total
String message = "Discount percent: " + discountPercent + "\n"
+ "Discount amount: " + discountAmount + "\n"
+ "Invoice total: " + total + "\n";
System.out.println(message);
// see if the user wants to continue
System.out.print ("Continue? (y/n): ");
choice = sc.next();
System.out.println();
// display the score count, score total, and average score
double numberInvoices = total += 1;
double averageInvoice = total /= invoiceCount;
double averageDiscount = discountAmount /= numberofInvoices;
System.out.println( + "Number of invoices: " + numberofInvoices + "\n");
System.out.println( + "Average invoice: " + averageInvoice + "\n");
System.out.println( + "Average discount: " + averageDiscount + "\n");
System.out.println(message);
}
}}
Re: invoiceApp help with coding
Please edit the post and wrap the code in code tags. See: BB Code List - Java Programming Forum
Can you post the program's output and explain what is wrong with it and show what it should be.