I am newbie at this, please try to be patient with me. I apologise in advance for the length of this post. In my class at school we have been trying out various loops in problems. The instructor calls the one we've been using a "Sentinel Loop". If there is another name for it I don't know what it is. :(
I can get it to accept the input and also the stopping statement. I can even get the program to tell me the sales tax and shipping "on an individual input".
The instructor wants to be able to input several figures and when the stopping statement is triggered, have the program show the total shipping cost and sales tax for all of the inputs together.
I have placed the math parts between the two input statements, and also outside of the loop.
My question is: "Do I need to put the math section into a method and if so where would I place the calling statement so that it would only work after the stop statement is triggered or would something else be even more appropriate?"
I have been beating my head against the wall for the last 10 days, and have not figured out an answer. I have tried everything I can think of.
Can someone either please answer the question or at least steer me to the information on how to do this type of a problem. I would appreciate it greatly.
This is the main body of my sentinel loop program. I can get it to work fine.
using System;
using System.Collections.Generic;
using System.Text;
namespace Exer4Chpt6
{
class Program
{
static void Main()
{
string inValue = "";
double salesAmount = 0;
double salesTax;
double shipAmount = 0;
double grdTotal;
const double INTEREST_RATE = .07;
double overAllTotal = 0;
double totalShippingAmt = 0;
double totalSalesTax = 0;
Console.WriteLine("Enter as many different sales amounts ");
Console.WriteLine("as you want. You will be shown the sales ");
Console.WriteLine("amount, sales tax, shipping amount, and ");
Console.WriteLine("the grand total. To Stop, enter");
Console.WriteLine(" -99");
Console.WriteLine();
Console.WriteLine("Please type in a sales amount.");
inValue = Console.ReadLine(); // Priming read, input before loop
while (inValue != "-99")
{
salesAmount = Convert.ToDouble(inValue);
salesTax = salesAmount * INTEREST_RATE;
Console.WriteLine("Please type in a sales amount.");
inValue = Console.ReadLine(); // reassigns data in inValue to check in loop
}
}
}
}
This is the math section of my program that I'm having the trouble with. The problem isn't in the math expressions themselves, but more in the placement to get it to do what I want
if (salesAmount < 250.01)
{
shipAmount = 5.0;
}
else if (salesAmount < 500.01)
{
shipAmount = 8.0;
}
else if (salesAmount < 1000.01)
{
shipAmount = 10.0;
}
else if (salesAmount <= 5000.00)
{
shipAmount = 15.0;
}
else if (salesAmount > 5000.00)
{
shipAmount = 20.0;
}
else
Console.WriteLine("Please type in a sales amount.");
grdTotal = salesAmount + shipAmount + salesTax;
overAllTotal += grdTotal;
totalShippingAmt += shipAmount;
totalSalesTax += salesAmount;
Console.WriteLine();
Console.WriteLine("Your final sales amount was: {0:C2}", grdTotal);
Console.WriteLine();
Console.WriteLine("Your sales tax amount was: {0:C2}", totalSalesTax);
Console.WriteLine();
Console.WriteLine("Your shipping amount was: {0:C2}", totalShippingAmt);
Console.WriteLine();
Console.WriteLine("Your total bill is: {0:C2} ", overAllTotal);
Console.WriteLine();
Any help will be very greatly welcome. Thank you.