Restaurant Billing Program
Nov 11, 2015 at 9:49pm UTC
I am stuck on how to get this program to work properly. It has to use information from a .dat file to calculate the Subtotal, Tax, Tip, and Total amount needed to be paid. All it does is continually spew numbers out.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
#include <iostream>
#include <fstream>
#define filename "orders.dat"
using namespace std;
int main()
{
float subtotal;
float salesTaxTotal;
float tipTotal;
float total;
double salesTax = .06;
double tipLow = .18;
double tipHigh = .20;
ifstream ins;
int num_people;
int orders;
int subtot = 0;
ins.open(filename);
if (ins.fail())
cerr << "ERROR: File Missing." << endl;
else
{
while (!ins.eof())
{
ins >> num_people;
ins >> orders;
subtot += orders;
cout << endl << "Subtotal:" << subtot << endl;
num_people = 0;
orders = 0;
for (int i=1; i <= num_people; i++)
{
ins >> num_people;
ins >> orders;
salestx = subtot * salesTax;
cout << endl << "Total Sales Tax:" << salestx << endl;
}
{
ins >> num_people;
ins >> orders;
if (num_people < 5)
tiptot = tipLow * subtot;
cout << endl << "Tip:" << lowtiptot << endl;
else (num_people >= 5)
tiptot = tipHigh * subtot;
cout << endl << "Tip:" << tiptot << endl;
}
{
ins >> num_people;
ins >> orders;
totbill = tiptot + salestx + subtot;
cout << endl << "Total Due:" << totbill < endl;
ins.read((char *)&num_people, 4);
}
}
}
return 0;
}
Topic archived. No new replies allowed.