Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
static void Main(string[] args)
{
    //Declare Variables
    Double purchasePrice = -1;
    Double discountPrice = 0;
    Double grandTotal = 0;
    Double itemNumber = 1;

    //Output outputs
    Console.Write("Welcome to our Firework Stand Checkout");

    //Do while loop
    do
    {
        Console.WriteLine("Enter the purchase price of the item (Enter -1 to Quit):  ");
        purchasePrice = Convert.ToDouble(Console.ReadLine());

        if (purchasePrice != -1)
        {
            if (purchasePrice >= 50)
            {
                discountPrice = purchasePrice * .90;
            }
            else
            {
                discountPrice = purchasePrice;
            }
            Console.WriteLine("Item number: ");
            itemNumber = itemNumber + 1;
            Console.WriteLine("Original cost is:  " + purchasePrice);
            Console.WriteLine("Discounted cost is:  " + discountPrice);

        }

    } while (purchasePrice != -1);

    Console.WriteLine("Your grand total is " + grandTotal);
    grandTotal = purchasePrice + discountPrice;
    Console.ReadLine();


What I have tried:

I have tried everything I could think of. I am just not sure how to get the information from the loop to calculate the grand total as you can see.
Posted
Updated 2-Jun-18 18:07pm

1 solution

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Code_ProjectConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            float purchasePrice = -1;
            float discountPrice = 0;
            float grandTotal = 0;
            float itemNumber = 1;

            //Output outputs
            Console.Write("Welcome to our Firework Stand Checkout\n \n");

            //Do while loop
            do
            {
                Console.WriteLine("Enter the purchase price of the item (Enter -1 to Quit):  ");
                purchasePrice = float.Parse(Console.ReadLine());

                if (purchasePrice != -1)
                {
                    if (purchasePrice >= 50)
                    {
                        discountPrice = purchasePrice * .90f;
                    }
                    else
                    {
                        discountPrice = purchasePrice;
                    }
                    grandTotal = grandTotal + discountPrice;
                    Console.WriteLine("Item number: ");
                    itemNumber = itemNumber + 1;
                    Console.WriteLine("Original cost is:  " + purchasePrice);
                    Console.WriteLine("Discounted cost is:  " + discountPrice);

                }

            } while (purchasePrice != -1);

            Console.WriteLine("Your grand total is " + grandTotal);
            
            Console.ReadLine();


        }
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900