Prime b

Prime b

  • NA
  • 810
  • 345k

Method help

Jan 15 2012 8:11 PM
Create a console-based application named
TaxCalculation. Include two overloaded methods—one
that accepts a price and a tax rate expressed as doubles
(for example, 79.95 and 0.06, where 0.06 represents 6%),
and one that accepts a price as a double and a tax rate as
an integer (for example, 79.95 and 6, where 6 also represents
6%). Include a Main() method that demonstrates
each method calculates the same tax amount appropriately.


So , if I input first number as double and second as int it works fine, but when i put two doubles then it gives me an error, I know it because of the code  i highlighted in yellow, but if I use ref parameters in my methods then for some reason only 1st method does all the math, and second method never does anything even if my first input is double and second is int....





      double price=0;
  int tax=0;

  calcTax(price, tax);
 
  }

  public static void calcTax( double price, double tax)
  {
  Console.WriteLine("Please enter price of the item");
  double itemPrice = Convert.ToDouble(Console.ReadLine());
  Console.WriteLine("Please now enter tax");
  double itemPriceTax = Convert.ToDouble(Console.ReadLine());

  double totalPrice;
  totalPrice = itemPrice * itemPriceTax/100;
  Console.WriteLine("Your item cost {0:C}, the1 tax for this item is {1:C}", itemPrice, totalPrice);
 
  }
  public static void calcTax( double price, int tax)
  {
  Console.WriteLine("Please enter price of the item");
  double itemPrice = Convert.ToDouble(Console.ReadLine());
  Console.WriteLine("Please now enter tax");
  int itemPriceTax = Convert.ToInt32(Console.ReadLine());

  double totalPrice;
  totalPrice = itemPrice * itemPriceTax/100;
  Console.WriteLine("Your item cost {0:C}, the2 tax for this item is {1:C}", itemPrice, totalPrice);

Answers (4)