0

I'll post my code after my questions.

1. Near the very end, I have DisplayIntroMessage() called for the event that the user desires another order. Is this all that I need to do to restart the process?

2. If that is all that is needed, what is the easiest way to save the total from each prior order(s) to add to newer ones.

3. In the DoTheMath() method, I am asking the user whether or not they desire another order? I'm not getting this to work out just right. I don't know what to do with it. I've tried several things only to end up unsuccessful in all of them.

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

namespace OrderCalculator
{
    public class OrderDetails
    {
        private int productChoice; //product number
        private int quant; //number of products order
        private double productValue; //monetary value for switch
        const double TAX_RATE = .0725; //used for taxes

        public void DisplayIntroMessage()
        {
            //Choose the product type
            Console.WriteLine("Welcome to the Ordering System.\n\n");
            Console.WriteLine("Start out by specifying which product you wish to order.\n");
            Console.WriteLine("Please enter a value from 1-4, depending on the product you choose: ");
            //convert user input to variable
            productChoice = Convert.ToInt16(Console.ReadLine());
            //determine how to proceed
            if (productChoice < 1 || productChoice > 4)
                do
                {
                    Console.WriteLine("Please enter a valid number.  It must be from 1-4: ");
                    productChoice = Convert.ToInt16(Console.ReadLine() );
                } while (productChoice < 1 || productChoice > 4);

            if (productChoice >= 1 && productChoice <= 5)
                //Choose the quantity
                Console.WriteLine("\nNow, choose how many of that product you wish to purchase: ");
                //convert user input to variable quant
                quant = Convert.ToInt16(Console.ReadLine()); 
        }

        //determine product chosen
        private void ProductChooser(int productChoice)
        {
            switch (productChoice)
            {
                case 1:
                    productValue = 2;
                    break;
                case 2:
                    productValue = 4;
                    break;
                case 3:
                    productValue = 6;
                    break;
                case 4:
                    productValue = 10;
                    break;
            }
        }

        public void DoTheMath()
        {
            //declare & assign value to totals
            double totalAmountDue = quant * productValue * TAX_RATE;
            double grandTotal;

            //determine whether or not 5% discount is applicable
            if (totalAmountDue >= 100)
                grandTotal = totalAmountDue * .95;
            else
            {
                grandTotal = totalAmountDue;
            }

            //give total to user
            Console.WriteLine("Your order totals $" + grandTotal);

            //determine whether or not user desires another order and follow through
            char anotherOrder;
            Console.WriteLine("Would you like another order? Enter yes or no");
            anotherOrder = Convert.ToChar(Console.ReadLine() );
            //if user enters an invalid choice...
            if (anotherOrder != "yes" || anotherOrder != "no")
                do
                {
                    Console.WriteLine("Please enter a valid choice.");
                    Console.WriteLine("It must be in the form of \"yes\" or \"no\".");
                    anotherOrder = Convert.ToChar(Console.ReadLine() );
                } while (anotherOrder != "yes" || anotherOrder != "no");
            //if the user says "no"...
            if (anotherOrder == "no")
                Console.WriteLine("Thank you for your order.  We hope you enjoy it!");
            //if the user says "yes"...
            if (anotherOrder == "yes")
                DisplayIntroMessage();
        }
    }
}
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by jatin24
0

I'll post my code after my questions.

1. Near the very end, I have DisplayIntroMessage() called for the event that the user desires another order. Is this all that I need to do to restart the process?

Yes that should restart the process.

2. If that is all that is needed, what is the easiest way to save the total from each prior order(s) to add to newer ones.

Are you trying to save individual orders? in that case you can make a global ArrayList and store whatever you want in there.
If you wish to permanently store the totals, you might have to use file IO.


3. In the DoTheMath() method, I am asking the user whether or not they desire another order? I'm not getting this to work out just right. I don't know what to do with it. I've tried several things only to end up unsuccessful in all of them.

your if statement is wrong.

if (anotherOrder != "yes" || anotherOrder != "no")
This will always return true no matter what you enter.
Also, you are using Convert.ToChar(), and comparing a string.
simply use the ReadLine() function to read the input. This will be in string.
change it something like this:

int flag = 0;

do
anotherOrder = Console.ReadLine();

if (anotherOrder == "yes" || anotherOrder == "Yes" || anotherOrder == "YES")
{
DisplayIntroMessage();
flag = 1;
}
else if (anotherOrder == "no" || anotherOrder == "No" || anotherOrder == "NO")
{
Console.WriteLine("Thank you for your order.  We hope you enjoy it!");
flag = 1;
}

else 
{
Console.WriteLine("Invalid input, please try again: ");
flag = 0;
}
}while(flag == 0);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.