Write a complete C++ program for WorldParking Sdn Bhd. to perform the following:

a. Write a return-value function named calcCharges() to calculate and return the parking charges for the customers. The company charges a RM1.00 minimum fee to park for up to one hour. An additional RM0.50 will be charged for each hour exceeding the first one hour. The maximum charge for any given 24-hour period is RM10.00. Assume that no car parks for longer than 24 hours at a time.

b. Write a void function named calcTotal() to calculate the total charges for all the customers.

c. Write the main program that allows the user to input number of customers and the hours parked for the customers. The program should use the function calcCharges()above to calculate the parking charges for each customer and function calcTotal() above to calculate the total charges for all the customers.

d. Finally, your program should output the parking charges for each customer and the total charges for all the customers. Use the appropriate parameters to pass values in and out of functions.

From https://www.daniweb.com/welcome/rules

Do provide evidence of having done some work yourself if posting questions from school or work assignments

With that out of the way, keep the question(s) to what you need help with. That is, that line of code that fails so we can narrow it down to that one thing that stopped you.

#include <iostream>
#include <cmath>
using namespace std;

double calcCharges(int hours){

    double totalcharges;

    if(hours<=19.0){
        totalcharges = (hours - 1) * 0.5 + 1;
    }else{
        totalcharges = 10.0;
    }

    return totalcharges;
}

void calctotal(double sum, float all[], int arraysize){

    int a;

    system ("CLS");

    for( a = 0; a < arraysize; a++){
        if(all[a] != 0){
            cout<<" Customer " <<a+1 <<" : RM" <<all[a] <<endl;     
        }
    }

    cout<< "Below Is the the total charges for all the customers: \n";
//  cout<< "RM " <<sum;

    cout<< "\n TOTAL :  " <<sum;
}

int main()
{
    int hour, choice, arraysize, continue1, i = 0;
    double total, sum;
    float all[] = { 0.0 };

    do{
        cout<<" Welcome to World Parking Sdn Bhd. Calculator System \n";
        cout<< " Please Select the action below: \n";
        cout<< " 1 : Add customer \n";
        cout<< " 2 : View Total \n";
        cin>>choice;

        switch(choice) { 
            case 1: 
                cout<<" Please enter the total our hour: \n";
                cin>>hour;

                total = calcCharges(hour);
                all[i] = total;
                i++;

                cout<< " Total charges: RM" <<total;
                cout<< "\n Enter 1 to continue, 2 to exit: \n";
                cin>>continue1; 

                choice = 0;

                //system ("CLS");

                break;

            case 2: 

                arraysize = sizeof(all);
                for(int a = 0; a < arraysize; a++){
                    sum += all[a];
                }
                calctotal(sum, all, arraysize);
                cout<<"\n\n THANK YOU BYEBYE";

                break; 

            default: 
                cout<< " Please Select the action below: (Please type 1 or 2)\n";
                cout<< " 1 : Add customer \n";
                cout<< " 2 : View Total \n";
        }

        system ("CLS");

    }
    while (continue1 == 1);

    arraysize = sizeof(all);
    for(int a = 0; a < arraysize; a++){
        sum += all[a];
    }
    calctotal(sum, all, arraysize);
    cout<<"\n\n THANK YOU BYEBYE";

}
commented: I thought it was buh-bye? https://en.wiktionary.org/wiki/buh-bye +15
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.