I ran into another problem using if looping.

What I want to do, in plain english, is if a variable is one thing (it will be Quit in this case), exit the program. Otherwise, I want it to ask for any other inputs and execute the program.

My code:

using System;
using SC = System.Console;

// Namespace
namespace payroll
{
    // Class
    class payroll
    {
        // Method start
        static void Main(string[] args)
        {
            // Declare variables
            double hoursWorked = 0.0, payRate = 0.0, grossPay = 0.0, stateTax = 0.0;
            double federalTax = 0.0, ficaTax = 0.0, netPay = 0.0;
            string hoursWorkedStr, payRateStr, empName;

            SC.WriteLine("Payroll Application");

            //Input
            SC.Write("\nPlease input Employee's Name (or Quit to end program): ");
            if(empName != Quit)
            {
                SC.Write("\nPlease input hours worked: ");
                hoursWorkedStr = Console.ReadLine();
                hoursWorked = Convert.ToDouble(hoursWorkedStr);

                SC.Write("\nPlease input rate of pay: ");
                payRateStr = Console.ReadLine();
                payRate = Convert.ToDouble(payRateStr);

                //Calculations
                grossPay = (hoursWorked * payRate);
                stateTax = (grossPay * 0.04);
                federalTax = (grossPay * 0.23);
                ficaTax = (grossPay * 0.14);
                netPay = (grossPay - (stateTax + federalTax + ficaTax));

                //Output
                SC.WriteLine("\nThe gross pay is:   {0:f}", grossPay);
                SC.WriteLine("\nThe state tax is:    {0:f}", stateTax);
                SC.WriteLine("\nThe federal tax is:  {0:f}", federalTax);
                SC.WriteLine("\nThe fica tax is:     {0:f}", ficaTax);
                SC.WriteLine("\nThe net pay is:     {0:f}", netPay);
                SC.WriteLine("\nEnd of Program");

            else
                return 0;   
            }

        }

    }
}

But everytime I try to use Quit, VS has a fit, same with else. Please help.

Your return type is void. If you change the method signature to return int, you should be good to go.

You're comparing to variables empName and Quit. I don't see a variable called Quit declared anywhere. If you wanted to compare it to the string "Quit", then it would look like this:

if (empName != "Quit")
{
    ...
}

Note that it is case-sensitive. If you want to ignore case, you can use the String.Equals() method that explicitly specifics a StringComparison.

Thank you, everyone

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.