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();
}
}
}