Discount Problem Please Help ASAP

Basically we have this program that asks the user to input the number of pages and number of copies he/she would like printed. There is also the option to have these pages stapled. Everything is working for me until I attempt to put in a discount. Our directions are if the Cost total for the job >=25.00 then the user recieves a discount. So far I can not get the Discount portion of the code to work, any ideas on what I'm doing wrong?


Here is the code:

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <string>
#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;


int main ()
{
    //constant declaration
    const double COST_TO_PRINT = .08; //cost to print per page
    const double STAPLE_COST = .02;   //cost of a staple

    //variable declaration
    int nCopies = 0;                 //number of copies
    int nPages = 0;                  //number of pages
    int Tpages = 0;                   //total to be printed
    double Tcost = 0.0;              //total cost
    char response = 'y' or 'n';
    double Tstaple = 0.0;
    double Discount = 0.0;
    double fCost = 0.0;
    double cTotal = 0.0;

    //greeting

    cout << "Print4u Printing Services"<<endl<<endl;


    //ask number of copies
    cout << "Enter number of copies: ";
    cin >> nCopies;
    if (nCopies <=0)
    {
        cout << "Invalid number of copies - must be >= 1"<<endl;
    exit(0);
    }

    //ask number of pages
    cout << "Enter number of pages: ";
    cin >> nPages;
    if (nPages <=0)
    {
        cout << "Invalid number of shares - must be >= 1"<<endl;
    }
    else if (nPages == 1)
    {
        cout << endl;
        nPages = 1;
    }
    else if (nPages >1)
    {
        cout << "Do you wish to staple each copy (y/n): ";
        cin >> response;
        cout << endl;

        if (response == 'y')
        {
            Tstaple = nCopies * STAPLE_COST;
        }
        else if (response == 'n')
        {
            Tstaple = 0;
        }
        else if (response = 'y' or 'n')
        {
            cout << "Invalid answer for stapling - must be y or n"<<endl<<endl;
            exit(0);
        }

    }


    //calculate ctotal
    cTotal = Tcost + Tstaple;

    //discount
    if (cTotal < 25.00)
    {
        Discount = 0;
    }
    else if (cTotal >= 25.00)
    {
        Discount = cTotal * .1;
    }


    //calculate number of pages
    Tpages = nCopies * nPages;

    //calculate cost
    Tcost = Tpages * COST_TO_PRINT;


    ////calculate ctotal
    cTotal = Tcost + Tstaple;

    //calculate fCost

    fCost =  cTotal - Discount;

    //print
    cout << fixed << showpoint << setprecision(2) << setw (12);
    cout <<"Cost Copies: " << Tcost <<endl;
    cout <<"Cost Stapling: " << Tstaple <<endl;
    cout <<"Cost Total: " << cTotal <<endl;
    cout <<"Discount: " << Discount <<endl;
    cout <<"=======" <<endl;
    cout <<"Cost Final: " << fCost <<endl;
    return 0;

    }
Last edited on
See

http://www.cplusplus.com/forum/beginner/79946/

It looks like you are working on the same problem.
Yes but we both are having separate problems :(
Did you check to see if the discount in his code works?
I took his way of doing it and used it in mine and it still wouldnt work. Though I've made some progress on mine.

1
2
3
4
5
6
7
8
if (cTotal >= 25.00)
    {
       discount = cTotal * .1;
    }
    else if (cTotal >= 25.00)
    {
        Discount = 15;
    }


it seems to skip the first if, because now my discount is always 15
Try this:

1
2
3
4
     cTotal = Tcost + Tstaple;    

     if (cTotal >= 25.00)
          discount = cTotal * .1;


Last edited on
Same result
I think that the Tcost formula on line 93 needs to be above line 76. Right now Tcost = 0 because the formula comes after it.
I think that the Tcost formula on line 93 needs to be above line 76. Right now Tcost = 0 because the formula comes after it.

This is correct.

1
2
Tpages = nCopies * nPages;
Tcost = Tpages * COST_TO_PRINT;


needs to be placed above cTotal = Tcost + Tstaple;

The way you have it now, Tcost will = 0, so you will need 1300 pages and 1300 copies to get your total cost over $25 to get the discount.
Last edited on
Good catch TheJJJunk! I missed the Tpages line.
Topic archived. No new replies allowed.