Please help me on this

i have code according to the output tht i have provided. Please help me where my mistakes are. The customer have to key in the number of person for each category. i have to use manipulators and if else.



#include<iostream>
#include <iomanip>

using namespace std;

int main()
{
int e, f, g, h;
double total, GTotal, disc, a, b, c, d;
const double a = 30.00, b = 40.00, c = 15.00, d = 0;

cout << "Category (number of person)" << endl;
cout << "Over 50 :";
cin >> e;
cout << "13 - 50 :";
cin >> f;
cout << "3 - 12 :";
cin >> g;
cout << "Under 3 :";
cin >> h;
cout << endl;

//calculation
if (e)
(e * a);
if (f)
(f * b);
if (g)
(g * c);
if (h)
(h * d);
total = (e + f + g + h);
if (disc)
(total * 0.1);
GTotal = total - disc;

cout << fixed << showpoint << setprecision(2);
cout << "Total :RM" << setw(10) << total << endl;
cout << "Discount (10%) :RM" << setw(10) << disc << endl;
cout << "----------------------------" << endl;
cout << "Grand Total :RM" << setw(10) << GTotal << endl;
cout << "----------------------------" << endl;



return 0;
}






Sample of Output:

Category (number of person):
Over 50 : 1
13 – 50 : 3
3 – 12 : 0
Under 3 : 1
-------------------------------------------
Over 50 : RM 30.00
13 – 50 : RM 120.00
3 – 12 : RM 0.00
Under 3 : RM 0.00
-------------------------------------------
Total : RM 150.00
Discount (10%) : RM 15.00
-------------------------------------------
Grand Total : RM……135.00
-------------------------------------------






1
2
3
4
5
6
7
8
if (e)
(e * a);
if (f)
(f * b);
if (g)
(g * c);
if (h)
(h * d);

1
2
if (disc)
(total * 0.1);

These statements do nothing, because you are not assigning anything.
Also if (number) is equivalent to if (number != 0)

Using single-letter variable names (outside of de facto standard naming schemes like 'i' in a loop) is a bad practice. Use more descriptive names.

Other than that, clearly the sample output shows more than what you're printing. So first step would at least be printing the static text that it want you to print.
Last edited on
Topic archived. No new replies allowed.