hi im new to programing and im trying to make a program that would calculate the tax on a given price but that would accept the tax rate as either an integer or a double but i get this error
Index (zero based) must be greater than or equal to zero and less than the size of the argument list
my code looks like this
using System;
public class TaxCalculation
{
public static void Main()
{
int rateI = 0;
double rateD;
double price;
string inputRate;
string inputPrice;
Console.Write("Please enter the price ");
inputPrice = Console.ReadLine();
price = Convert.ToDouble(inputPrice);
Console.Write("Please enter the tax rate ");
inputRate = Console.ReadLine();
rateD = Convert.ToDouble(inputRate);
if (rateD > 0)
rateI = Convert.ToInt32(rateD);
if (rateI != 0)
Calculation(price, rateI);
else
Calculation(price, rateD);
Console.Write("Press enter to exit");
Console.ReadLine();
}
public static void Calculation(double price, int rateI)
{
double taxrate;
double tax;
double total;
taxrate = rateI / 100;
tax = price * taxrate;
total = price + tax;
Console.WriteLine("The tax on {0}$ is {1}$ and The total is {3}$", price, tax, total);
}
public static void Calculation(double price, double rateD)
{
double total;
double tax;
tax = price * rateD;
total = price + tax;
Console.WriteLine("The tax on {0}$ is {1}$ and The total is {3}$", price, tax, total);
}
}