C Examples

WAP in C that simulates working of telephone bill company!

The Program in C that simulates working of telephone bill company is given below:

#include <stdio.h>

#define LOCAL_CALL_RATE 0.5
#define LONG_DISTANCE_CALL_RATE 1.5
#define INTERNATIONAL_CALL_RATE 5.0

struct customer {
    char name[50];
    int local_call_duration;
    int long_distance_call_duration;
    int international_call_duration;
};

double calculate_bill(struct customer* c) {
    double local_call_charge, long_distance_call_charge, international_call_charge, total_bill;

    local_call_charge = c->local_call_duration * LOCAL_CALL_RATE;
    long_distance_call_charge = c->long_distance_call_duration * LONG_DISTANCE_CALL_RATE;
    international_call_charge = c->international_call_duration * INTERNATIONAL_CALL_RATE;
    total_bill = local_call_charge + long_distance_call_charge + international_call_charge;

    return total_bill;
}

void print_bill(struct customer* c, double bill) {
    printf("Telephone Bill for %s\n", c->name);
    printf("Local Call Duration: %d minutes\n", c->local_call_duration);
    printf("Long Distance Call Duration: %d minutes\n", c->long_distance_call_duration);
    printf("International Call Duration: %d minutes\n", c->international_call_duration);
    printf("Total: $%.2lf\n", bill);
}

int main() {
    struct customer c;
    double bill;

    printf("Enter customer name: ");
    scanf("%s", c.name);

    printf("Enter Local call duration (minutes): ");
    scanf("%d", &c.local_call_duration);

    printf("Enter Long Distance call duration (minutes): ");
    scanf("%d", &c.long_distance_call_duration);

    printf("Enter International call duration (minutes): ");
    scanf("%d", &c.international_call_duration);

    bill = calculate_bill(&c);
    print_bill(&c, bill);

    return 0;
}

Output:

Enter customer name: KUMAR
Enter Local call duration (minutes): 10
Enter Long Distance call duration (minutes): 30
Enter International call duration (minutes): 30
Telephone Bill for KUMAR
Local Call Duration: 10 minutes
Long Distance Call Duration: 30 minutes
International Call Duration: 30 minutes
Total: $200.00

Pro-Tips💡

This program uses a struct to represent a customer, and the struct contains the customer’s name and the duration of their local, long-distance, and international calls.

The main() function prompts the user to enter the customer’s information, which is read using scanf().

The calculate_bill() function is then called and passed a pointer to the customer struct.

It calculates the total bill by multiplying the call durations by the appropriate rates and adding up the charges.

The print_bill() function is then called and passed a pointer to the customer struct and the bill, it then prints the customer’s name, call durations, charges and total bill using printf().

Learn C-Sharp ↗

C-sharp covers every topic to learn about C-Sharp thoroughly.

Learn C Programming ↗

C-Programming covers every topic to learn about C-Sharp thoroughly.

Learn C++ Programming↗

C++ covers every topic to learn about C-Sharp thoroughly.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

C# Program to Delete Element at Desired position From Array

The Program in C# Program to Delete Element at Desired position From Array is given below: Output: Hello Codeauri Family, enter the number of elements in the array:4Enter…

Leave a Reply

Your email address will not be published. Required fields are marked *

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X