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");

            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);

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

                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");

                return 0;   



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

5 Years
Discussion Span
Last Post by tboctavan

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.