Microsoft Visual C 2015 In a YouDoIt section of this chapter

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

Solution

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

Microsoft Visual C# 2015 In a \
Microsoft Visual C# 2015 In a \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site