C# Programming: A. Create a console-based application named TippingTable.cs that
ID: 669609 • Letter: C
Question
C# Programming:
A. Create a console-based application named TippingTable.cs that lets restaurant patrons approximate the correct tip for meals. Prices range from $10 to $100, and tipping percentage rates range from 10% to 25%. The program uses several loops. The program prompts restaurant patrons for user input:
Lowest tipping percentage
Highest tipping percentage
Lowest possible restaurant bill
Highest possible restaurant bill
B. Write a GUI program named TippingTableGUI that creates a tipping table after the user clicks a button. Get the lowest and highest tipping percentages and the lowest and highest possible restaurant bills from TextBox entries.
Explanation / Answer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace restaurant
{
class Program
{
static void Main(string[] args)
{
int i,tp,b,ltp, htp, lb, hb;
tp = 0;
for (i = 1; i < 5; i++)
{
Console.WriteLine("Lowest tipping percentage");
ltp = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Highest tipping percentage");
htp = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Lowest possible restaurant bill");
lb = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Highest possible restaurant bill");
hb = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter Bill amount");
b = Convert.ToInt32(Console.ReadLine());
if (b >= lb && b <= (hb / 2))
tp = b * ltp / 100;
else if (b > hb / 2 && b <= hb)
tp = b * htp / 100;
Console.WriteLine("Tip amount is " + tp);
Console.ReadKey();
}
}
}
}
B.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace restarent_gui
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
}
private void label4_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int i, tp, b, ltp, htp, lb, hb;
tp = 0;
ltp = Convert.ToInt32(textBox1.Text );
htp = Convert.ToInt32(textBox2.Text );
lb = Convert.ToInt32(textBox3.Text );
hb = Convert.ToInt32(textBox4.Text );
b = Convert.ToInt32(textBox5.Text );
if (b >= lb && b <= (hb / 2))
tp = b * ltp / 100;
else if (b > hb / 2 && b <= hb)
tp = b * htp / 100;
DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[0].Clone();
row.Cells[0].Value = b;
row.Cells[1].Value = tp;
dataGridView1.Rows.Add(row);
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.