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

Microsoft Visual C# 2015 In a \"YouDoIt\" section of this chapter, you created a

ID: 3795455 • Letter: M

Question

Microsoft Visual C# 2015

In a "YouDoIt" section of this chapter, you created a tipping table for patrons to use when analyzing their restaraunt bills. Now, create a modified program where the highest/lowest tipping percentage and highest/lowing possible restaraunt bill (4 values total) are obtained from user input.

Code from previous exercise provied below:

using static System.Console
class TippingTable
{
static void Main()
{
double dinnerPrice = 10.00;
double tipRate;
double tip;

const double LOWRATE = .10;
const double MAXRATE = .25;
const double TIPSTEP = .05;
const double MAXDINNER = 100.00;
const double DINNERSTEP = 10.00;

Write(" Price");
for (tipRate = LOWRATE; tipRate <= MAXRATE; tipRate += TIPSTEP)
Write("{0, 8}", tipRate.ToString("F"));
WriteLine();
WriteLine("----------------------------------------");

tipRate = LOWRATE;

while(dinnerPrice <= MAXDINNER)
{
Write("{0, 8}", dinnerPrice.ToString("C"));
while (tipRate <= MAXRATE)
{
tip = dinnerPrice * tipRate;
Write("{0, 8}", tip.ToString("F"));
tipRate += TIPSTEP;
}
dinnerPrice += DINNERSTEP;
tipRate = LOWRATE;
WriteLine();
}
}
}

Explanation / Answer

using static System.Console
class TippingTable
{
static void Main()
{
double dinnerPrice = 10.00;
double tipRate;
double tip;

double LOWRATE = .10;
double MAXRATE = .25;
const double TIPSTEP = .05;
double MAXDINNER = 100.00;
const double DINNERSTEP = 10.00;
//Take input from user
Console.Write("Please Enter the Lowest Tip Rate");
LOWRATE = double.Parse(Console.ReadLine());
Console.Write("Please Enter the Highest Tip Rate");
MAXRATE = double.Parse(Console.ReadLine());
Console.Write("Please Enter the Lowest Restaurant Bill");
dinnerPrice = double.Parse(Console.ReadLine());
Console.Write("Please Enter the Highest Restaurant Bill");
MAXDINNER = double.Parse(Console.ReadLine());

Console.Write(" Price");
for (tipRate = LOWRATE; tipRate <= MAXRATE; tipRate += TIPSTEP)
Console.Write("{0, 8}", tipRate.ToString("F"));
Console.WriteLine();
Console.WriteLine("----------------------------------------");

tipRate = LOWRATE;

while(dinnerPrice <= MAXDINNER)
{
Console.Write("{0, 8}", dinnerPrice.ToString("C"));
while (tipRate <= MAXRATE)
{
tip = dinnerPrice * tipRate;
Console.Write("{0, 8}", tip.ToString("F"));
tipRate += TIPSTEP;
}
dinnerPrice += DINNERSTEP;
tipRate = LOWRATE;
Console.WriteLine();
}
}
}
}