Write a C Program to calculate the bill of a job done as follows:
a) Rate of typing 3 Rs/page
b) Printing of 1st copy 5 Rs/page & later every copy 3 Rs/page.

The user should enter the number of pages and print out copies he/she wants. (Use if-else statement)

This is one of the easiest programs, if you know the concept of if-else conditional statement. In this program, calculating the typing bill is easy but there’s a trick (logic) you will use to calculate printing bill.

For example, if there only 1 page needs to be copied then the copying bill will be 5 but if the user wants 2 copies then for first page Rs 5 will be charged and for every other copy Rs 4 will be charged. Thus, total copying bill for 2 pages will be Rs. 9 only. 😀

Tutorial 📺

Watch tutorial and learn how to solve this problem. 😉

Steps

To calculate the bill of job done

  1. First of all, display the rates of typing and printing pages. Next, accept two numbers from the user and store the values in copy and type variables. The copy variable will store the number of copies a user want and type will store the number of pages to be typed.
  2. Now, check if (type<0) then display the message “Invalid Typing pages Value Entered.” otherwise as per the given rate calculate the typing bill and store it in type variable.
  3. Again, check if (copy<0) then display the message “Invalid Printing pages Value Entered.” otherwise calculate the printing bill as per the given rates. For first page the printing price is Rs. 5 and later for every copy the price is Rs. 3/page.
  4. Finally, display the total bill which includes both typing and printing bills.

Code 💻

#include<stdio.h>
#include<conio.h>

void main()
{
  int copy = 0, type = 0;
  clrscr();
  printf("\tXerox Shop Services");
  printf("\na) Rate of typing is 3 Rs/page.");
  printf("\nb) Print of 1st copy is 5 Rs/page & later every copy is 3 Rs/page.");
  printf("\n\nPlease enter the number of typing pages: ");
  scanf("%d", &type);
  printf("\n\nPlease enter the number of copies: ");
  scanf("%d", &copy);
  if(type<0)
    printf("\nInvalid Typing pages Value Entered.");
  else
    type *= 3;
  if(copy<0)
    printf("\nInvalid Printing pages Value Entered.");
  else if(copy>=1)
      copy = 5 + (--copy * 3);
  printf("\n\nTyping Charges: %d", type);
  printf("\nPrinting Charges: %d", copy);
  printf("\n=====================");
  printf("\nTotal Bill: %d", type + copy);
  getch();
}

Example 😍

Let’s assume, the user enters 2 and 5 for typing and printing, respectively.

First of all, it will check if value in type variable is less than 0 or not. If yes then it will display the message that “Invalid Typing pages Value Entered” otherwise it will calculate the typing bill i.e. Rs. 6 ( Rs. 3 * 2 pages).

Same way it will check if value in copy variable is less than 0 or not. If yes then it will display the appropriate error message otherwise it will calculate the printing (copying) bill i.e. Rs. 17 (For 1st copy Rs. 5 + for remaining copies Rs 3 * 4 = Rs. 12).

Finally, it will display the total bill of job done i.e. Typing Charges: 6 and Printing Charges: 17 and Total Bill: 23.

This is how we write C program to calculate the bill of a job done. For more C program, click here.

Categorized in: