I'm making a Console application and I have one while loop to restart the whole program when the paycheck is calculated and another while loop to re-asks the questions about what type of paycheck the user receives if the input is wrong. But when I enter the incorrect option the question is asked again and the whole program restarts too. Is there a way to have the second while loop react separately from the first while loop?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WageCalc
{
class Program
{
static void Main(string[] args)
{
//Variables
string hourWorkedInput;
string wageInput;
double hourlyWage = 0.00;
int hoursWorkedAWeek = 0;
double payCheck;
bool wageCalculated = false;
bool AskQuestion = true;
//Actual Code
while (wageCalculated == false)
{
Console.WriteLine("Welcome to the Monthly Wage Calculator");
Console.WriteLine("Please enter how much you are paid an hour");
wageInput = Console.ReadLine();
hourlyWage = Double.Parse(wageInput);
Console.WriteLine("Please enter how many hours you work a week");
hourWorkedInput = Console.ReadLine();
hoursWorkedAWeek = Int32.Parse(hourWorkedInput);
Console.WriteLine("Do you get paid (W)eekly or (B)iweekly?");
string often = Console.ReadLine();
//Repeats if input is incorrect
while(AskQuestion)
{
if (often == "W")
{
payCheck = hoursWorkedAWeek * hourlyWage;
Console.WriteLine("You will make {0} on every paycheck", payCheck);
Console.WriteLine("Would you like to Calculate another Paycheck?");
string repeat = Console.ReadLine();
switch (repeat)
{
case "Y":
wageCalculated = false;
break;
case "N":
wageCalculated = true;
break;
default:
wageCalculated = true;
break;
}
}
else if (often == "B")
{
payCheck = (hoursWorkedAWeek * 2) * hourlyWage;
Console.WriteLine("You will make {0} on every paycheck", payCheck);
Console.WriteLine("Would you like to Calculate another Paycheck?");
string repeat = Console.ReadLine();
switch (repeat)
{
case "Y":
wageCalculated = false;
break;
case "N":
wageCalculated = true;
break;
default:
wageCalculated = true;
break;
}
}
else
{
Console.WriteLine("Please pick W or B");
AskQuestion = false;
}
}
}
}
}
}