Here is the link to the programming question for detail. I have done my source code but I don't know how to calculate and display how many times inputs are entered in sentinel loop. Here is my source code:
#include <iostream>
using namespace std;
int main() {
int i, hours;
int tot_clients = 0;
float charges;
float tot_collection = 0;
const int sentinel = -1;
cout << "Welcome to ABC Parking Services Sdn Bhd" << endl;
cout << "=======================================" << endl;
while (hours != sentinel) {
cout << "Please enter number of parking hours (-1 to stop)" << endl;
cin >> hours;
if (hours <= 2 && hours > 0) {
charges = 1.00 * hours;
cout << "Charges: " << charges << endl;
}
else if (hours > 2 && hours <= 12) {
charges = (1.00 * 2) + ((hours - 2) * 0.50);
cout << "Charges: " << charges << endl;
}
else if (hours > 12) {
charges = 10.00 * hours;
cout << "Charges: " << charges << endl;
}
else if (hours == sentinel) {
break;
}
tot_collection = tot_collection + charges;
}
cout << "SUMMARY OF REPORT" << endl;
cout << "=======================================" << endl;
cout << "Total clients:" << tot_clients << endl;
cout << "Total colletion:" << tot_collection << endl;
return 0;
}
Hope someone can help me solving this. I am studying for my programming final exam.
I understand you want to count the number of clients (tot_clients). You have already intitalised the tot_clients = 0. This is good. You just have to increment the tot_clients variable inside the while loop (tot_clients++).