C Program to Calculate Telephone Call Bills

« C Tutorial C Examples »

In this tutorial, we will learn about how to create a program in C that will ask from user to enter total number of telephone calls made in 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.

// Write a program in C, that will accept the
// no of calls (unit say per minute) made
// and print the amount payable, using following condition:
// First 200 calls are Free.
// Next 300 calls are @ Rs.1/unit.
// And rest calls are @ Rs.2/unit.

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 = Rs.%d", charge);
            tempNoOfCall = noOfCall - 500;
            charge = tempNoOfCall * 2;
            charge = charge + 300;
            printf("The charge you have to paid = Rs.%d", charge);
    return 0;

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

c program calculate phone call bills

Here user has to enter that how many number of calls (total number of unit or minutes) that he/she has made in the previous month. For example, let's suppose that the telephone user has made total of 167 minutes of phones calls in previous month. Therefore, user has to supply the input as 167 and then press 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

As the first 200 calls or minutes of talk are free and user has only made total of 167 minutes of call, therefore no charge he/she has to be paid for the previous month. Here is another sample run, but this time user has crossed the limit of free 200 calls:

print phone calls charge c program

Here is another sample run. This time let's suppose that the user has made total of 2460 minutes of calls in 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 above program:

« C Tutorial C Examples »


Quick Links
Signup - Login - Give Online Test