H.Cornerstone
CAGiversary!
- Feedback
- 1 (100%)
If anyone with C# could help me on this problem, It would be awesome. I have to create a program that will accept a input value and then use if else statements to calculate the total amount based on discounts depending on the input value.
class Program
{
static void Main()
{
int purchAmount;
int discount;
InputValues(out purchAmount);
discount = DetermineDiscount(purchAmount);
PrintResults(discount, purchAmount);
}
public static void InputValues(out int purch)
{
string inputValue;
Console.WriteLine("Please Enter Purchased Amount");
// prompt user to enter purchased amount
inputValue = Console.ReadLine();
purch = Convert.ToInt32(inputValue);
}
public static int DetermineDiscount(int purchAmount)
{
int discount;
if (purchAmount > 200)
{
discount = 20;
}
else if (purchAmount > 150)
{
discount = 15;
}
else if (purchAmount > 100)
{
discount = 10;
}
else if (purchAmount > 50)
{
discount = 5;
}
else if (purchAmount > 0)
{
discount = 0;
}
else
{
Console.WriteLine("The entered purchase amount is negative. It's discount amount cannot be computed.");
}
return discount;
}
public static void PrintResults(int discount, int purchAmount)
{
Console.WriteLine("The Discount is: " + discount);
Console.WriteLine("The Total Amount is: " + (purchAmount - DetermineDiscount(purchAmount)));
Console.ReadLine();
}
}
}
class Program
{
static void Main()
{
int purchAmount;
int discount;
InputValues(out purchAmount);
discount = DetermineDiscount(purchAmount);
PrintResults(discount, purchAmount);
}
public static void InputValues(out int purch)
{
string inputValue;
Console.WriteLine("Please Enter Purchased Amount");
// prompt user to enter purchased amount
inputValue = Console.ReadLine();
purch = Convert.ToInt32(inputValue);
}
public static int DetermineDiscount(int purchAmount)
{
int discount;
if (purchAmount > 200)
{
discount = 20;
}
else if (purchAmount > 150)
{
discount = 15;
}
else if (purchAmount > 100)
{
discount = 10;
}
else if (purchAmount > 50)
{
discount = 5;
}
else if (purchAmount > 0)
{
discount = 0;
}
else
{
Console.WriteLine("The entered purchase amount is negative. It's discount amount cannot be computed.");
}
return discount;
}
public static void PrintResults(int discount, int purchAmount)
{
Console.WriteLine("The Discount is: " + discount);
Console.WriteLine("The Total Amount is: " + (purchAmount - DetermineDiscount(purchAmount)));
Console.ReadLine();
}
}
}