C# project - This exercise called TippingTable.cs (or create a project named Tip
ID: 669814 • Letter: C
Question
C# project - This exercise called TippingTable.cs (or create a project named TippingTable) is based on the You Do It section of the 6th Edition textbook chapter pages 207-210. Your output tipping table should look similar to the figure below here. Your assignment is to modify (or create if you did not do the "You Do It") a version of an app calledTippingTable.cs (as mentioned in the first sentence of this exercise). Your version should prompt the user for the following 4 values rather than having them declared and initialized as constants as it did in the "You Do It". The 4 values are: 1) The lowest tipping percentage (.10 or 10%), 2) The highest tipping percentage (.25 or 25%), 3) The lowest possible restaurant (dinner) bill ($10), and 4) The highest restaurant (dinner) bill ($100).
*************************************************************************
"You Do It"
using System;
namespace TippingTable
{
class Program
{
static void Main(string[] args)
{
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Black;
Console.Clear();
double dinnerPrice = 10.00;
double tipRate;
double tip;
const double LOWRATE = 0.10;
const double MAXRATE = 0.25;
const double TIPSTEP = 0.05;
const double MAXDINNER = 100.00;
const double DINNERSTEP = 10.00;
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 += 0.05;
}
dinnerPrice += DINNERSTEP;
tipRate = LOWRATE;
Console.WriteLine();
}
}
}
}
Explanation / Answer
using System;
namespace TippingTable
{
class Program
{
static void Main(string[] args)
{
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Black;
Console.Clear();
Console.WriteLine("Enter Dinner Price "dinnerPrice);
double tipRate;
double tip;
Console.WriteLine("Enter Lowest Percentage Rate " LOWRATE);
Console.WriteLine("Enter highest tipping percentage " MAXRATE);
Console.WriteLine("Enter lowest possible restaurant (dinner) bill " TIPSTEP);
Console.WriteLine("Enter highest restaurant (dinner) bill " MAXDINNER);
Console.WriteLine(DINNERSTEP);
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 += 0.05;
}
dinnerPrice += DINNERSTEP;
tipRate = LOWRATE;
Console.WriteLine();
Console.ReadLine();
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.