Click here to Skip to main content
15,889,595 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have to write a ComputeSalesTax() method that receives a sales amount and a tax rate, and calculates and it displays the sales tax in the following format 'The tax on 100.00 at 10% is 10.00'.

What I have tried:

This is what I got:

using System;
class Program
{
    static void ComputeSalesTax(double saleAmount, double taxRate, double tax)
    {
        saleAmount = 100;
        taxRate = 10;
        tax = taxRate * saleAmount; 
        Console.WriteLine("The tax on {0} at {1} is {2}",
        saleAmount.ToString("C"),
        taxRate.ToString("P"), tax.ToString("F"));
    }
}


I'm not sure if I'm correct because I seem to get the following error:

Error CS5001: Program does not contain a static 'Main' method suitable for an entry point.
Posted
Updated 30-May-18 8:06am
Comments
[no name] 30-May-18 17:35pm    
tax = (taxRate * saleAmount) / 100.0;

1 solution

Every C# application .EXE file must contain an entry point - it's where the application begins executing when you try to run it. Without that entry point, it's not a EXE file (though it can still be an Assembly, but don't worry about that for the moment - you'll get to it later)

The entry point you need it a method called Main which can call your new function. Oh, and by the way - your homework calls for two parameters, not three!
using System;

namespace GeneralTestingConsole
    {
    class Program
        {
        public static void Main()
            {
            ComputeSalesTax(100.0, 10.0);
            ComputeSalesTax(100.0, 17.5);
            }
        static void ComputeSalesTax(double saleAmount, double taxRate)
            {
            double tax = taxRate * saleAmount;
            Console.WriteLine("The tax on {0} at {1} is {2}",
                              saleAmount.ToString("C"),
                              taxRate.ToString("P"), tax.ToString("F"));
            }
        }
    }
 
Share this answer
 
v2
Comments
John R. Shaw 30-May-18 15:11pm    
Do not forget to remove the hard code "saleAmount = 100" and "taxRage = 10". Those are supplied as the parameters to the function.
OriginalGriff 31-May-18 1:57am    
:doh:
Fixed, thanks!
Member 13652359 31-May-18 8:01am    
The output is wrong from the code above:

The tax on $100.00 at 1,000.00% is 1000.00
The tax on $100.00 at 1,750.00% is 1750.00


When the output should be:

The tax on 100.00 at 10% is 10.00
OriginalGriff 31-May-18 8:20am    
Yes. And why is that, do you think?
After all, you wrote that part...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900