im having trouble with this code can anyone tell me what I'm doing wrong?
using System;
namespace JenkinsNutShop
{
class NutSales
{
static void Main()
{
// this is where I am listing the name of the business:
Console.WriteLine("JENKINS NUT SHOP");
string customerName;
double pounds;
double subTotal = 0;
string nutName = "";
char nutType;
double totalPrice;
double tax;
GetUserInput(out customerName, out nutType, out pounds);
CalcNutCosts(pounds, nutType, ref subTotal, ref nutName, out totalPrice, out tax);
DisplayReceipt(pounds,nutName,subTotal, tax, totalPrice);
}
public static void GetUserInput(out string customerName, out char nutType, out double pounds)
{
string userin;
// Prompting user for type of nuts they want to purchase:
Console.WriteLine(); //this is making a blank line
// Prompting user for the number of pounds they are ordering :
// Prompting user to input pounds of puchase
Console.Write("Customer name: ");
customerName = Console.ReadLine();
Console.WriteLine("What type of nuts would you like?");
Console.WriteLine("Please type an upper case letter or lower case letter to represent the nuts you wish to buy");
Console.WriteLine("Type in the letter \"C\" for Cashews");
Console.WriteLine("Type in the letter \"A\" for Almonds");
Console.WriteLine("Type in the letter \"P\" for Peanuts");
Console.WriteLine("Type in the letter \"W\" for Walnuts");
Console.WriteLine(); // enters a black line
Console.Write("Nut Type: ");
userin = Console.ReadLine();
nutType = Convert.ToChar(userin);
Console.Write("How many pounds would you like? ");
userin = Console.ReadLine();
pounds = Convert.ToDouble(userin);
}
public static void CalcNutCosts(double pounds, char nutType, ref double subTotal, ref string nutName, out double totalPrice, out double tax)
{
const double CASHEWS = 6.50;
const double ALMONDS = 7.25;
const double PEANUTS = 2.39;
const double WALNUTS = 2.79;
switch(nutType)
{
case'C':
case'c':
subTotal = pounds * CASHEWS;
nutName = "Cashew";
break;
case'A':
case'a':
subTotal = pounds * ALMONDS;
nutName = "Almonds";
break;
case'P':
case'p':
subTotal = pounds * PEANUTS;
nutName = "Peanuts";
break;
case'W':
case'w':
subTotal = pounds * WALNUTS;
nutName = "Walnuts";
break;
tax = subTotal * .0675;
totalPrice = subTotal + tax;
}
}
public static void DisplayReceipt(double pounds,string nutName,double subTotal, double tax, double totalPrice)
{
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Your receipt:");
Console.WriteLine();
Console.WriteLine("{0} pounds of {1} nuts. Subtotal \t {2:C}", pounds, nutName, subTotal);
Console.WriteLine(" Tax \t {0:C}",tax);
Console.WriteLine(" Total \t {0:C}",totalPrice);
Console.WriteLine();
Console.WriteLine("Thank you for shopping at Jenkins Nut Shop \n \n");
}
}
}
2006-12-27
04:44:40
·
4 answers
·
asked by
Sad Mom
3
in
Programming & Design