Jump to content

keeping a running total

Go to solution Solved by fizzlesticks,

itemPriceTotal=+itemPrice should be itemPriceTotal+=itemPrice

import java.util.Scanner;public class CashRegister{    public static void main(String[]args)    {        Scanner scan = new Scanner(System.in);        System.out.print("Please enter the name of an item: ");        String userItem = scan.next();                double itemPriceTotal = 0;        while(!userItem.equals("quit"))        {            System.out.println("Please enter the price of the item: ");            int itemPrice = scan.nextInt();                        itemPriceTotal=+itemPrice;                        System.out.print("Please enter the name of an item: ");            userItem = scan.next();        }        System.out.println(itemPriceTotal);    }        public static void printReceipt(int subtotal, int tax, int total)    {        System.out.println("Subtotal        " + "$" + subtotal);        System.out.println("Tax             " + "$" + tax);        System.out.println("-------------------------------");        System.out.println("Total           " + "$" + total);    }}

I can't seem to remember how to keep a running total of numbers. Basically this program prompts the user for the name of an item and then the price for the item. What I want to do is keep a running total of the price of the items and then eventually print it out. What exactly am I doing wrong here? Thanks for your help!

Link to comment
https://linustechtips.com/topic/268542-keeping-a-running-total/
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×