I just started my intro to programming class last week, and my professor ran out of time to check my work for a grade (pass/fail) so could someone check this code for me and see if it looks correct?
Code:
// This program calculates your total Restaurant Bill
// Inputs : mealCharge
// taxRate
// tipRate
// Outputs : mealCharge
// taxAmount
// tipAmount (calculate meal cost + tax)
// totalBill
#include <iostream>
#include <iomanip>
using namespace std;
void main()
{
// Input variables
double mealCharge, taxRate, tipRate;
// Output variables
double taxAmount, tipAmount, totalBill;
// set formatting
cout << fixed << setprecision (2) << showpoint;
// Get the cost of the meal.
cout << "What is the total cost of your meal?";
cin >> mealCharge;
// Get the tax rate.
cout << "What is the local tax rate?";
cin >> taxRate;
// Get the tip rate.
cout << "What is the suggested tip rate?";
cin >> tipRate;
taxRate = (taxRate / 100);
tipRate = (tipRate / 100);
taxAmount = taxRate * mealCharge;
tipAmount = tipRate * (mealCharge + taxAmount);
totalBill = mealCharge + taxAmount + tipAmount;
//Calculate the input
cout << "Your meal starts at $" << mealCharge;
cout << ".\n";
cout << "Your tax is $" << taxAmount;
cout << ".\n";
cout << "Your tip is $" << tipAmount;
cout << ".\n";
cout << "Your total charge is $" << totalBill;
cout << ".\n";
}
Last edited by a moderator: