Program to calculate telephone bill

Telephone bill calculator

Program description

Program to find the telephone bill as per the following rules -:
Call Range Bill
<=100 Rs./- 0 per call
101-200 Rs./- 1 per call
201-300 Rs./- 0.50 per call
301-500 Rs./- 0.20 per call
>500 Rs./- 0.10 per call
Rental Charges Rs./- 130

C Program

#include
#define RENTAL 130
int main() {
 int nc;
 float bill;
 printf("Enter the number of calls: ");
 scanf("%d",&nc);
 
 if(nc <= 100) {
  bill = 0;
 } else if(nc <= 200) {
  bill = (nc - 100) * 1 + 0;
 } else if(nc <= 300) {
  bill = (nc - 200) * 0.50 + 100 + 0;
 } else if(nc <= 500) {
  bill = (nc - 300) * 0.20 + 50 + 100 + 0;
 } else {
  bill = (nc - 500) * 0.10 + 40 + 50 + 100 + 0;
 }
 
 //final bill including rental
 
 bill += RENTAL;
 
 printf("Total bill = %.2f",bill);
 return 0;
}

C++ Program

#include
#define RENTAL 130
using namespace std;
int main() {
 int nc;
 float bill;

 cout << "Enter the number of calls: ";
 cin >> nc;
 
 if(nc <= 100) {
  bill = 0;
 } else if(nc <= 200) {
  bill = (nc - 100) * 1 + 0;
 } else if(nc <= 300) {
  bill = (nc - 200) * 0.50 + 100 + 0;
 } else if(nc <= 500) {
  bill = (nc - 300) * 0.20 + 50 + 100 + 0;
 } else {
  bill = (nc - 500) * 0.10 + 40 + 50 + 100 + 0;
 }
 
 //final bill including rental
 
 bill += RENTAL;
 
 cout << "Total bill = " << bill;
 return 0;
}

Java Program

import java.util.Scanner;
class CalcBill {
 public static void main(String args[]) {
  int nc;

  final int RENTAL = 130;
  
  Scanner sc = new Scanner(System.in);
  System.out.print("Enter the number of calls: ");
  nc = sc.nextInt();

  float bill;
  if(nc <= 100) {
   bill = 0;
  } else if(nc <= 200) {
   bill = (nc - 100) * 1 + 0;
  } else if(nc <= 300) {
   bill = (nc - 200) * 0.50f + 100 + 0;
  } else if(nc <= 500) {
   bill = (nc - 300) * 0.20f + 50 + 100 + 0;
  } else {
   bill = (nc - 500) * 0.10f + 40 + 50 + 100 + 0;
  }
  
  bill += RENTAL;
  
  System.out.println("Total bill = "+bill);
 }
}

Go Lang

package main
import "fmt"

func main() {
 var nc int
 const RENTAL = 130
 
 fmt.Print("Enter the number of calls: ");
 fmt.Scan(&nc)
 
 var bill float32
 
 if nc <= 100 {
  bill = 0
 } else if nc <= 200 {
  bill = float32((float32(nc) - 100) * 1 + 0)
 } else if nc <= 300 {
  bill = float32((float32(nc) - 200) * 0.50 + 100 + 0)
 } else if nc <= 500 {
  bill = float32((float32(nc) - 300) * 0.20 + 50 + 100 + 0)
 } else {
  bill = float32((float32(nc) - 500) * 0.10 + 40 + 50 + 100 + 0)
 }
 
 bill += RENTAL
 
 fmt.Println("Total bill = ",bill)
}

PHP

define('RENTAL',130);

if(isset($_POST['sub'])) {
 $nc = $_POST['nc'];

 if($nc <= 100) {
  $bill = 0;
 } else if($nc <= 200) {
  $bill = ($nc - 100) * 1 + 0;
 } else if($nc <= 300) {
  $bill = ($nc - 200) * 0.50 + 100 + 0;
 } else if($nc <= 500) {
  $bill = ($nc - 300) * 0.20 + 50 + 100 + 0;
 } else {
  $bill = ($nc - 500) * 0.10 + 40 + 50 + 100 + 0;
 }
 
 $bill += RENTAL;

 echo "Total bill = ".$bill;
}

Comments

Popular posts from this blog

String in golang

Inline V/S Block Level Element

Floating point Data types in Go lang

Escape Sequence | Formatted Printing | Interview Questions

Program to check a year is leap year or not.

Printing in C programming

Arrays in C Language

Operators in C Language| Part-4

Sum of two numbers

Data types in Java