would you please help with my program calculation?

I can get my program to run and everything looks right except i cannot seem to get the parking fee to calculate to the right amount. this is what i have so far:
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
114
115
116
117
118
119
120
/*                                                                                   // A-1-1-01

Author:              Ima Coder                                                       // A-1-1-02

Date Written:        December 11, 2011                                               // A-1-1-02

Course:              CSIS 123, Internet                                              // A-1-1-02

Program:             Task 09-02, Chapter 6                                           // A-1-1-02

Program Description: This application calculates and displays the parking charges    // A-1-1-02

                     for each customer who parked in the garage on a given day.      // A-1-1-02

                     The garage charges a $2.00 minimum fee to park for up to three  // A-1-1-02

                     hours, and an additional $0.50 per hour for each hour or        // A-1-1-02

                     part thereof in excess of three hours.                          // A-1-1-02

                     The maximum charge for any given 24-hour period is $10.00.      // A-1-1-02

                     Assume that no car parks for longer than 24 hours at a time.    // A-1-1-02

Compiler Used:       Microsoft Visual C++ 2010 Express                               // A-1-1-02

SourceFile Name:     Garage.cpp                                                      // A-1-1-02

*/                                                                                   // A-1-1-03

#include <iostream>                                                                  // A-1-1-04

#include <iomanip>                                                                   // A-1-1-05

#include <string>                                                                    // A-1-1-06

#include <cmath>                                                                     // A-1-1-07

#include <cstdlib>                                                                   // A-1-1-08

using namespace std;                                                                 // A-1-1-09

class Garage {                                                                       // A-1-1-10

public:                                                                              // A-1-1-11

   void prepareDailyReceiptsReport() {                                               // A-1-1-12

    int hoursParkedByCustomer[c_customerCount];                                      // A-1-3-001 TODO

       int customerNumber;                                                           // A-1-3-002

	   double totalParkingReceipts = 0;                                              // A-1-3-003 TODO

    double parkingCharge;                                                              // A-1-3-004 TODO

	bool usedMaximumParkingCharge = false;                                            // A-1-3-005 TODO

	bool usedMinimumParkingCharge = false;                                          // A-1-3-006 TODO

    getDailyParkingActivity(hoursParkedByCustomer);                                 // A-1-3-007 TODO

       cout << "\n\nToday's Parking Receipts:\n";                                    // A-1-3-008

       displayColumnHeadings();                                                      // A-1-3-009

       for (customerNumber=1;customerNumber<=getCustomerCount();customerNumber++) {  // A-1-3-010

           parkingCharge =                                            // A-1-3-011 TODO
               calculateCustomerParkingCharge                 // A-1-3-012 TODO
               (hoursParkedByCustomer[customerNumber - 1],                                            // A-1-3-013 TODO
               usedMaximumParkingCharge,                                        // A-1-3-014 TODO
               usedMinimumParkingCharge);                                               // A-1-3-015 TODO

        totalParkingReceipts += parkingCharge;                                    // A-1-3-016 TODO
		displayThisCustomer                                             // A-1-3-017 TODO
		   (customerNumber,                                            // A-1-3-018 TODO
           hoursParkedByCustomer[customerNumber-1],                 // A-1-3-019 TODO
            parkingCharge,                                          // A-1-3-020 TODO
            usedMaximumParkingCharge,                                     // A-1-3-021 TODO
            usedMinimumParkingCharge);                                        // A-1-3-022 TODO

       } // for                                                                      // A-1-3-023
      displayReportSummaryLine(totalParkingReceipts, "Total Receipts");           // A-1-3-024 TODO

       displayReportSummaryLine                                                   // A-1-3-025 TODO

           (totalParkingReceipts/getCustomerCount(), "Average Fee");                // A-1-3-026 TODO

   } // function prepareDailyReceiptsReport                                          // A-1-1-13

private:                                                                             // A-1-1-14

   const static int c_customerColumnWidth = 8;                                       // A-1-1-15

   const static int c_customerCount = 30;                                            // A-1-1-16

   const static int c_defaultChargeColumnWidth = 7;                                  // A-1-1-17

   const static int c_interColumnWidth = 3;                                          // A-1-1-18

   const static int c_hoursParkedColumnWidth = 6;                                    // A-1-1-19

   const static int c_parkingChargeColumnWidth  = 7;                                 // A-1-1-20

   double calculateCustomerParkingCharge                                                 // A-1-1-21 TODO
	             ( double hoursParked,                                                         // A-1-1-22 TODO
           bool &usedMaximumParkingCharge,                                              // A-1-1-23 TODO
             bool &usedMinimumParkingCharge){                                    // A-1-1-24 TODO
         const double c_minimumParkingCharge = 2.0;                                       // A-1-3-027 TODO
          const double c_maximumParkingCharge = 10.0;                                     // A-1-3-028 TODO
          const double c_maximumParkingHoursForMinimumParkingCharge = 3.0;                // A-1-3-029 TODO
          const double c_chargePerHourAfterMinimum = 0.5;                                // A-1-3-030 TODO
          double parkingCharge = c_minimumParkingCharge;                                // A-1-3-031 TODO
          if (hoursParked > c_minimumParkingCharge)                               // A-1-3-032 TODO
            parkingCharge =                                                           // A-1-3-033 TODO
                  c_minimumParkingCharge + c_chargePerHourAfterMinimum               // A-1-3-034 TODO
					 * ceil(hoursParked                                                  // A-1-3-035 TODO
						 - c_maximumParkingHoursForMinimumParkingCharge);               // A-1-3-036 TODO
 
Last edited on
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
114
115
116
117
118
119
120
121
122
123
124
125
126
        if ( parkingCharge == c_maximumParkingCharge) {                                   // A-1-3-037 TODO
            usedMaximumParkingCharge = true;                                          // A-1-3-038 TODO
           parkingCharge = c_maximumParkingCharge;                                     // A-1-3-039 TODO
		 } else                                                                       // A-1-3-040 TODO
           usedMaximumParkingCharge = false;                                      // A-1-3-041 TODO
         if (parkingCharge == c_minimumParkingCharge)                                 // A-1-3-042 TODO
           usedMinimumParkingCharge = true;                                         // A-1-3-043 TODO
		 else                                                                         // A-1-3-044 TODO
            usedMinimumParkingCharge = false;                                       // A-1-3-045 TODO
          return parkingCharge;                                                          // A-1-3-046 TODO
   } // function calculateCustomerParkingCharge                                            // A-1-1-25 TODO
   void displayColumnHeadings() {                                                    // A-1-1-26

       cout << "\n\t" << right                                                       // A-1-3-047

          << setw(getCustomerColumnWidth()) << "Customer"                            // A-1-3-048

          << setw(getInterColumnWidth()) << " "                                      // A-1-3-049

          << setw(getHoursParkedColumnWidth()) << "Hours "                           // A-1-3-050

          << setw(getInterColumnWidth()) << " "                                      // A-1-3-051

          << setw(getParkingChargeColumnWidth()) << "Parking"                        // A-1-3-052

          << setw(getInterColumnWidth()) << " "                                      // A-1-3-053

          << setw(getDefaultChargeColumnWidth()) << "Default";                       // A-1-3-054

       cout << "\n\t" << right                                                       // A-1-3-055 TODO

          << setw(getCustomerColumnWidth()) << "Number"                             // A-1-3-056 TODO

          << setw(getInterColumnWidth()) << " "                                       // A-1-3-057 TODO

          << setw(getHoursParkedColumnWidth())<< "Parked"                           // A-1-3-058 TODO

          << setw(getInterColumnWidth())<< " "                                      // A-1-3-059 TODO

          << setw(getParkingChargeColumnWidth()) << "Fee  "                             // A-1-3-060 TODO

          << setw(getInterColumnWidth()) << " "                                     // A-1-3-061 TODO

          << setw(getDefaultChargeColumnWidth()) << "Charge "                         // A-1-3-062 TODO

          << "\n";                                                                    // A-1-3-063 TODO
   } // function displayColumnHeadings                                               // A-1-1-27
//displayReportSummaryLine (reportSummaryAmount: double, reportSummaryLabel: String)

 void displayReportSummaryLine                                                              // A-1-1-28 TODO

         (double reportSummaryAmount,                                                      // A-1-1-29 TODO

           string reportSummaryLabel){                                                   // A-1-1-30 TODO

           const int c_reportSummaryRightIndentWidth =                         // A-1-3-064 TODO

             (getCustomerColumnWidth()                                        // A-1-3-065 TODO

             + getHoursParkedColumnWidth()                                  // A-1-3-066 TODO

             + 2 * getInterColumnWidth()                                     // A-1-3-067 TODO

             - reportSummaryLabel.length());                               // A-1-3-068 TODO

           cout << "\n\n\t" <<right                                     // A-1-3-069 TODO

			  << reportSummaryLabel                                            // A-1-3-070 TODO

              << fixed << showpoint << setprecision(2)                        // A-1-3-071 TODO

              << setw(c_reportSummaryRightIndentWidth) << right << " "                                // A-1-3-072 TODO

              << setw(getParkingChargeColumnWidth()) << reportSummaryAmount;              // A-1-3-073 TODO

 } // function displayReportSummary                                           // A-1-1-31 TODO
  void displayThisCustomer                                                          // A-1-1-32

       (int customerNumber,                                                          // A-1-1-33

        int hoursParked,                                                             // A-1-1-34

        double parkingCharge,                                                        // A-1-1-35

        bool usedMaximumParkingCharge,                                               // A-1-1-36

        bool usedMinimumParkingCharge) {                                             // A-1-1-37

           string defaultChargeLiteral;                                              // A-1-3-074

           if (usedMaximumParkingCharge == true)                                     // A-1-3-075

             defaultChargeLiteral = "Maximum";                                       // A-1-3-076

           else                                                                      // A-1-3-077

             if (usedMinimumParkingCharge == true)                                   // A-1-3-078

               defaultChargeLiteral = "Minimum";                                     // A-1-3-079

             else                                                                    // A-1-3-080

               defaultChargeLiteral = "--   ";                                       // A-1-3-081

           cout << "\n\t" << right                                                 // A-1-3-082 TODO

              << fixed << showpoint << setprecision(2)                            // A-1-3-083 TODO

              << setw(getCustomerColumnWidth()) << customerNumber          // A-1-3-084 TODO

              << setw(getInterColumnWidth()) << " "                            // A-1-3-085 TODO

              << setw(getHoursParkedColumnWidth()) << hoursParked               // A-1-3-086 TODO

              << setw(getInterColumnWidth()) << " "                           // A-1-3-087 TODO

              << setw(getParkingChargeColumnWidth()) << parkingCharge           // A-1-3-088 TODO

              << setw(getInterColumnWidth()) << " "                             // A-1-3-089 TODO

              << setw(getDefaultChargeColumnWidth()) << defaultChargeLiteral;     // A-1-3-090 TODO
           if (customerNumber % 5 == 0)                                               // A-1-3-091 TODO

             cout << "\n";                                                          // A-1-3-092 TODO

   } // function displayThisCustomer                                                 // A-1-1-38 
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
   int getCustomerCount() {                                                          // A-1-1-39

       return c_customerCount;                                                       // A-1-3-093

   } // function getCustomerCount                                                    // A-1-1-40

   int getCustomerColumnWidth() {                                                    // A-1-1-41

       return c_customerColumnWidth;                                                 // A-1-3-094

   } // function getCustomerColumnWidth                                              // A-1-1-42

   void getDailyParkingActivity(int hoursParkedByCustomer[]) {                       // A-1-1-43

       const int c_maximumHoursParked = 24;                                          // A-1-3-095

       srand(12321);                                                                 // A-1-3-096

       for (int customerNumber=1;customerNumber<=getCustomerCount();                 // A-1-3-097

           customerNumber++) {                                                       // A-1-3-097

         hoursParkedByCustomer[customerNumber-1] = 1 + rand() % c_maximumHoursParked;// A-1-3-098

       } // for                                                                      // A-1-3-099

   } // function getDailyParkingActivity                                             // A-1-1-44

   int getDefaultChargeColumnWidth() {                                               // A-1-1-45

       return c_defaultChargeColumnWidth;                                            // A-1-3-100

   } // function getChargeColumnWidth                                                // A-1-1-46

   int getHoursParkedColumnWidth() {                                                 // A-1-1-47

       return c_hoursParkedColumnWidth;                                              // A-1-3-101

   } // function getHoursParkedColumnWidth                                           // A-1-1-48

   int getInterColumnWidth() {                                                       // A-1-1-49

       return c_interColumnWidth;                                                    // A-1-3-102

   } // function getInterColumnWidth                                                 // A-1-1-50

   int getParkingChargeColumnWidth() {                                               // A-1-3-51

       return c_parkingChargeColumnWidth;                                            // A-1-3-103

   } // function getParkingChargeColumnWidth                                         // A-1-1-52

}; // class Garage                                                                   // A-1-1-53

int main() {                                                                         // A-1-5-01

    Garage myGarage;                                                                  // A-1-5-02 TODO

    string enterKey;                                                                 // A-1-5-03

    cout << "\nTask 09-02, Ch06, Programmed by Ima Coder";                           // A-1-5-04

    myGarage.prepareDailyReceiptsReport();                                            // A-1-5-05 TODO

    cout << ("\n\nEnd of Program: Press <Enter> to exit program.");                  // A-1-5-06

    getline(cin, enterKey);                                                          // A-1-5-07

} // function main                                                                   // A-1-5-08 

and i need it to look like this:
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
Task 09-02, Ch06, Programmed by Ima Coder

 

Today's Parking Receipts:

 

        Customer   Hours    Parking   Default

          Number   Parked     Fee     Charge

 

               1       18      9.50     --

               2       19     10.00     --

               3       23     10.00   Maximum

               4        6      3.50     --

               5       23     10.00   Maximum

 

               6       13      7.00     --

               7        3      2.00   Minimum

               8        4      2.50     --

               9       19     10.00     --

              10       14      7.50     --

 

              11        6      3.50     --

              12       16      8.50     --

              13        7      4.00     --

              14        5      3.00     --

              15       11      6.00     --

 

              16       19     10.00     --

              17       15      8.00     --

              18        4      2.50     --

              19        2      2.00   Minimum

              20       22     10.00   Maximum

 

              21        7      4.00     --

              22       24     10.00   Maximum

              23        3      2.00   Minimum

              24       23     10.00   Maximum

              25       14      7.50     --

 

              26       19     10.00     --

              27        5      3.00     --

              28       20     10.00   Maximum

              29        2      2.00   Minimum

              30       21     10.00   Maximum

 

 

        Total Receipts       198.00

 

        Average Fee            6.60

 

End of Program: Press <Enter> to exit program. 

but my program comes out like this:
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
Task 09-02, Ch06, Programmed by Ima Coder
Today's Parking Receipts:

        Customer   Hours    Parking   Default
          Number   Parked     Fee     Charge

               1       18      9.50     --
               2       19     10.00   Maximum
               3       23     12.00     --
               4        6      3.50     --
               5       23     12.00     --

               6       13      7.00     --
               7        3      2.00   Minimum
               8        4      2.50     --
               9       19     10.00   Maximum
              10       14      7.50     --

              11        6      3.50     --
              12       16      8.50     --
              13        7      4.00     --
              14        5      3.00     --
              15       11      6.00     --

              16       19     10.00   Maximum
              17       15      8.00     --
              18        4      2.50     --
              19        2      2.00   Minimum
              20       22     11.50     --

              21        7      4.00     --
              22       24     12.50     --
              23        3      2.00   Minimum
              24       23     12.00     --
              25       14      7.50     --

              26       19     10.00   Maximum
              27        5      3.00     --
              28       20     10.50     --
              29        2      2.00   Minimum
              30       21     11.00     --


        Total Receipts       209.50

        Average Fee            6.98

End of Program: Press <Enter> to exit program. 
Last edited on
Im having a hard time on this one. Feel like I am understanding less and less of what I am doing in these programs

I am also having a problem with the dollar charge. Every line is 2 dollars.
Last edited on
@andywassup

Shouldn't this
1
2
3
4
5
6
7
8
9
10
 if ( parkingCharge == c_maximumParkingCharge) {                                   // A-1-3-037 TODO
            usedMaximumParkingCharge = true;                                          // A-1-3-038 TODO
           parkingCharge = c_maximumParkingCharge;                                     // A-1-3-039 TODO
		 } else                                                                       // A-1-3-040 TODO
           usedMaximumParkingCharge = false;                                      // A-1-3-041 TODO
         if (parkingCharge == c_minimumParkingCharge)                                 // A-1-3-042 TODO
           usedMinimumParkingCharge = true;                                         // A-1-3-043 TODO
		 else                                                                         // A-1-3-044 TODO
            usedMinimumParkingCharge = false;                                       // A-1-3-045 TODO
          return parkingCharge;                          


look like this?
1
2
3
4
5
6
7
8
9
10
11
 if ( parkingCharge >= c_maximumParkingCharge) {    //    be >= , not ==
            usedMaximumParkingCharge = true;                                          // A-1-3-038 TODO
           parkingCharge = c_maximumParkingCharge;                                     // A-1-3-039 TODO
		 } else                                                                       // A-1-3-040 TODO
           usedMaximumParkingCharge = false;                                      // A-1-3-041 TODO
         if (parkingCharge <= c_minimumParkingCharge) { // be <= , not == and be in braces like Maximum
           usedMinimumParkingCharge = true;
           parkingCharge = c_minimumParkingCharge;            // added to give variable the value 
           }	 else                                                                         // A-1-3-044 TODO
            usedMinimumParkingCharge = false;                                       // A-1-3-045 TODO
          return parkingCharge;                          


well I wrote them how I have it because these are the instructions i have for those lines(I dont know if i followed them right or not but i tought so:
A-1-3-032) If (hours parked exceeds hours parked for minimum charge)

A-1-3-033) ASSIGN value of expression (c_minimumParkingCharge PLUS c_chargePerHourAfterMinimum

A-1-3-034) MULTIPLIED BY the expression ceil(hoursParked

A-1-3-035) MINUS c_maximumParkingHoursForMinimumParkingCharge))

A-1-3-036) TO parkingCharge



A-1-3-037) if (parking charge exceeds maximum allowed parking charge)

A-1-3-038) ASSIGN value of true TO usedMaximumParkingCharge

A-1-3-039) ASSIGN value of c_maximumParkingCharge TO parkingCharge

A-1-3-040) ELSE

A-1-3-041) ASSIGN value of false TO usedMaximumParkingCharge


A-1-3-042) if (parking charge is the same as minimum parking charge)

A-1-3-043) ASSIGN value of true TO usedMinimumParkingCharge

A-1-3-044) ELSE

A-1-3-045) ASSIGN value of false TO usedMinimumParkingCharge



A-1-3-046) RETURN parkingCharge

Ok changing the lines labeled: A-1-3-037) A-1-3-042) worked to get my numbers right but now I cant get the right maximum and minimum labels to line up. This is what mine looks like now:

Task 09-02, Ch06, Programmed by Andrya Newman

Today's Parking Receipts:

        Customer   Hours    Parking   Default
          Number   Parked     Fee     Charge

               1       18      9.50     --
               2       19     10.00   Maximum
               3       23     10.00   Maximum
               4        6      3.50     --
               5       23     10.00   Maximum

               6       13      7.00     --
               7        3      2.00   Minimum
               8        4      2.50     --
               9       19     10.00   Maximum
              10       14      7.50     --

              11        6      3.50     --
              12       16      8.50     --
              13        7      4.00     --
              14        5      3.00     --
              15       11      6.00     --

              16       19     10.00   Maximum
              17       15      8.00     --
              18        4      2.50     --
              19        2      2.00   Minimum
              20       22     10.00   Maximum

              21        7      4.00     --
              22       24     10.00   Maximum
              23        3      2.00   Minimum
              24       23     10.00   Maximum
              25       14      7.50     --

              26       19     10.00   Maximum
              27        5      3.00     --
              28       20     10.00   Maximum
              29        2      2.00   Minimum
              30       21     10.00   Maximum


        Total Receipts       198.00

        Average Fee            6.60

End of Program: Press <Enter> to exit program.
Psych, I know what you mean! I actually am going in for help today. Hopefully he will kind of explain what is going on. I am trying my best to understand what we are doing but usually me getting these programs done are by looking up everything on the internet and getting help with my errors or it is just luck.
I finally found a (=) I was missing. My program now looks like yours. the max and the minimum look right. it should be on every 2 and every 10. I think the example is wrong. I am going to email the teacher to see if I am right.
I believe the example program is correct, though. The instructions state that the first 3 hours of parking are $2. Every hour after that is $0.50. So if you break down 19 hours it is $2 + .50(16) which comes out to exactly $10. This does not exceed the maximum, and I suppose the "default charge" only applies to those numbers that were originally greater than $10 and defaulted back down to $10. It shouldn't count those who come out evenly to $10 as one that was defaulted.

Hope that makes sense :/

Something like this should work, I think?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 if ( parkingCharge > c_maximumParkingCharge) 
{    
            usedMaximumParkingCharge = true;                                       
            parkingCharge = c_maximumParkingCharge;                                   
} 
if ( parkingCharge == c_maximumParkingCharge) 
{
            usedMaximumParkingCharge = false;
            parkingCharge = c_maximumParkingCharge; //returns the maximum value but tells the program not to mark it as defaulted
} 
else                                                                       
           usedMaximumParkingCharge = false;                                      
if (parkingCharge <= c_minimumParkingCharge) 
{ 
           usedMinimumParkingCharge = true;
           parkingCharge = c_minimumParkingCharge;            
}	 
else                                                                         
            usedMinimumParkingCharge = false;                                       
          return parkingCharge;
Last edited on
Thanks Programming Noob. Your Awesome,
You did solve my programing problem.
The first line is a >
That changed my program to match the example. I do not agree yet with the last if statement. The directions say
if (parking charge is the same as minimum parking charge
Wouldn't that mean that it would be---?
If (parkingCharge == c_minimumParkingCharge);
Last edited on
Topic archived. No new replies allowed.