Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

*****I want the question to be in a loop, so if user enters p( which is invalid

ID: 3586685 • Letter: #

Question

*****I want the question to be in a loop, so if user enters p( which is invalid becuase the options are either y or n )the question comes up again if they would like to calculate their bonus, also I want the system to end when the user enters n...this program is done in c#

using System;

public class Test

{

//function definitions

public static void salary_incr1(double salary,double bonusRate)

{

double new_salary = salary + salary *bonusRate;

Console.WriteLine(" The $"+salary+" salary with a "+ bonusRate +"% bonus increment is: $"+new_salary);

}

public static void salary_incr2(double salary,int bonus)

{

double new_salary = salary + bonus;

Console.WriteLine(" The $"+salary+" salary plus a $"+bonus +" bonus is: $"+new_salary);

}

public static void Main()

{

double salary,rate;

int bonus;

string option;

Console.WriteLine(" Would you like to calculate salary bonuses [y/n]? ");

option = Console.ReadLine();

if(option == "y")

{

Console.WriteLine(" Enter the salary:");

salary = Convert.ToDouble(Console.ReadLine());

Console.WriteLine(" Enter the increase rate:");

rate = Convert.ToDouble(Console.ReadLine());

Console.WriteLine(" Enter the salary bonus amount (integer value): ");

bonus = Convert.ToInt32(Console.ReadLine());

//function calls

salary_incr1(salary,rate);  

salary_incr2(salary,bonus);

}

}

}

Explanation / Answer

Hi

I have added the code and highlighted the code changes below

using System.IO;
using System;
public class Test
{
//function definitions
public static void salary_incr1(double salary,double bonusRate)
{
double new_salary = salary + salary *bonusRate;
Console.WriteLine(" The $"+salary+" salary with a "+ bonusRate +"% bonus increment is: $"+new_salary);
}
public static void salary_incr2(double salary,int bonus)
{
double new_salary = salary + bonus;
Console.WriteLine(" The $"+salary+" salary plus a $"+bonus +" bonus is: $"+new_salary);
}
public static void Main()
{
double salary,rate;
int bonus;
string option;
Console.WriteLine(" Would you like to calculate salary bonuses [y/n]? ");
option = Console.ReadLine();
while(option != "y" && option != "n") {
Console.WriteLine(" Would you like to calculate salary bonuses [y/n]? ");
option = Console.ReadLine();  
}
while(option == "y")

{
Console.WriteLine(" Enter the salary:");
salary = Convert.ToDouble(Console.ReadLine());
Console.WriteLine(" Enter the increase rate:");
rate = Convert.ToDouble(Console.ReadLine());
Console.WriteLine(" Enter the salary bonus amount (integer value): ");
bonus = Convert.ToInt32(Console.ReadLine());
//function calls
salary_incr1(salary,rate);  
salary_incr2(salary,bonus);
Console.WriteLine(" Would you like to calculate salary bonuses [y/n]? ");
option = Console.ReadLine();
while(option != "y" && option != "n") {
Console.WriteLine(" Would you like to calculate salary bonuses [y/n]? ");
option = Console.ReadLine();  
}

}
}
}

Output:

Result