C Program to Calculate Telephone Call Bills

In this tutorial, we will learn how to create a program in C that will ask the user to enter the total number of telephone calls made in a particular month. Here, "number of telephone calls" means "number of minutes." After receiving the total number of phone calls made in a month, the program will calculate and print the payable amount (for that month) as per the given call rate:

Let's take a look at the program.

int main()
    int noOfCall, tempNoOfCall, charge;
    printf("Enter total unit of calls made this month: ");
    scanf("%d", &noOfCall);
        printf("You have not crossed the limit of 200 calls");
        printf("\nNo charge.");
            tempNoOfCall = noOfCall - 200;
            charge = tempNoOfCall * 1;
            printf("The charge you have to paid = %d", charge);
            tempNoOfCall = noOfCall - 500;
            charge = tempNoOfCall * 2;
            charge = charge + 300;
            printf("The charge you have to paid = %d", charge);
    return 0;

Because the above program was written in the Code::Blocks IDE, here is the similar output you will see on your output screen after a successful build and run; this is the first snapshot of the sample run:

c program calculate phone call bills

The user must enter the number of calls (total number of units or minutes) made in the previous month here. Assume, for example, that the telephone user made 167 phone calls in the previous month. Therefore, the user has to supply the input as 167 and then press the ENTER key to see the charge that has to be paid for the previous month, as shown in the second snapshot of the sample run given here:

c program print phone calls bill

Because the first 200 calls or minutes of talk are free, and the user has only made 167 minutes of calls, there is no charge for the previous month. Here is another sample run, but this time the user has crossed the limit of 200 free calls:

print phone calls charge c program

Here is another sample run. This time, let's suppose that the user has made a total of 2460 minutes of calls in the previous month. Therefore, the charge is shown in the sample run given below:

print phone call bill c program

Here are some of the main steps used in the above program:

C Quiz

« Previous Program Next Program »

Liked this post? Share it!