C program to generate electricity bill
Generate an electricity bill based on the number of units consumed by the user. If more units are consumed, the rate per unit charge also increases.
Applied logicIf the user consumes the lowest unitis as follows:
if (units < 50){ amt = units * 3.50; unitcharg = 25; }
Applied logicIf the unit is between 50 and 100is as follows As shown −
else if (units <= 100){ amt = 130 + ((units - 50 ) * 4.25); unitcharg = 35; }
If the units are between 100 and 200, the logic applied is as follows-
else if (units <= 200){ amt = 130 + 162.50 + ((units - 100 ) * 5.26); unitcharg = 45; }
The logic appliedIf the number of units exceeds 200 is as follows As stated −
amt = 130 + 162.50 + 526 + ((units - 200 ) * 7.75); unitcharg = 55;
Therefore, the final amount will be generated as per the following logic-
total= amt+ unitcharg;
Example
The following is the C program to generate the electricity bill-
Live demonstration
#include <stdio.h> int main(){ int units; float amt, unitcharg, total; printf(" Enter no of units consumed : "); scanf("%d", &units); if (units < 50){ amt = units * 3.50; unitcharg = 25; }else if (units <= 100){ amt = 130 + ((units - 50 ) * 4.25); unitcharg = 35; }else if (units <= 200){ amt = 130 + 162.50 + ((units - 100 ) * 5.26); unitcharg = 45; }else{ amt = 130 + 162.50 + 526 + ((units - 200 ) * 7.75); unitcharg = 55; } total= amt+ unitcharg; printf("electricity bill = %.2f", total); return 0; }
Output
When the above program is executed, the following results are produced-
Enter no of units consumed: 280 electricity bill = 1493.50
The above is the detailed content of C program to generate electricity bill. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Given below is a C language algorithm to convert Roman numerals to decimal numbers: Algorithm Step 1 - Start Step 2 - Read Roman numerals at runtime Step 3 - Length: = strlen(roman) Step 4 - For i=0 to Length-1 Step 4.1-switch(roman[i]) Step 4.1.1-case'm': &nbs

Generating random data is very important in the field of data science. From building neural network predictions, stock market data, etc., date is usually used as one of the parameters. We may need to generate random numbers between two dates for statistical analysis. This article will show how to generate k random dates between two given dates using the random and datetime modules. Datetime is Python’s built-in library for handling time. On the other hand, the random module helps in generating random numbers. So we can combine random and datetime modules to generate a random date between two dates. Syntax random.randint (start, end, k) random here refers to the Python random library. The randint method uses three important

How to use PHP to generate refreshable image verification codes. With the development of the Internet, in order to prevent malicious attacks and automatic machine operations, many websites use verification codes for user verification. One common type of verification code is the image verification code, which generates a picture containing random characters and requires the user to enter the correct characters before proceeding. This article will introduce how to use PHP to generate refreshable image verification codes and provide specific code examples. Step 1: Create a verification code image First, we need to create a verification code image

Linked lists use dynamic memory allocation, i.e. they grow and shrink accordingly. They are defined as collections of nodes. Here, a node has two parts, data and links. The representation of data, links and linked lists is as follows - Types of linked lists There are four types of linked lists, as follows: - Single linked list/Singly linked list Double/Doubly linked list Circular single linked list Circular double linked list We use the recursive method to find the length of the linked list The logic is -intlength(node *temp){ if(temp==NULL) returnl; else{&n

Hyperbolic functions are defined using hyperbolas instead of circles and are equivalent to ordinary trigonometric functions. It returns the ratio parameter in the hyperbolic sine function from the supplied angle in radians. But do the opposite, or in other words. If we want to calculate an angle from a hyperbolic sine, we need an inverse hyperbolic trigonometric operation like the hyperbolic inverse sine operation. This course will demonstrate how to use the hyperbolic inverse sine (asinh) function in C++ to calculate angles using the hyperbolic sine value in radians. The hyperbolic arcsine operation follows the following formula -$$\mathrm{sinh^{-1}x\:=\:In(x\:+\:\sqrt{x^2\:+\:1})}, Where\:In\:is\:natural logarithm\:(log_e\:k)

The rename function changes a file or directory from its old name to its new name. This operation is similar to the move operation. So we can also use this rename function to move files. This function exists in the stdio.h library header file. The syntax of the rename function is as follows: intrename(constchar*oldname,constchar*newname); The function of the rename() function accepts two parameters. One is oldname and the other is newname. Both parameters are pointers to constant characters that define the old and new names of the file. Returns zero if the file was renamed successfully; otherwise, returns a nonzero integer. During a rename operation

What to do if word table of contents is generated incorrectly. With the development of technology, electronic documents have become an indispensable part of our daily work and study. When editing electronic documents, especially long articles or papers, the generation of a table of contents is a very important step. The table of contents can make it easier for readers to find the content and structure of the article and improve reading efficiency. However, sometimes we encounter some problems in the process of generating the catalog, such as catalog generation errors, disordered order, etc. So, if the word directory is generated incorrectly, how should we solve it? head

How to generate an error book for online answering questions In today's information age, answering questions online has become a common task for many students and educators. Wrong questions have always been one of the problems in the learning process. Many people hope to easily generate a wrong answer book for online answers so that they can better review and master knowledge. This article will introduce how to realize the generation function of online answer error book through programming, and provide specific code examples. Step 1: Build a web interface to generate online answer and error booklets. You need a web interface to display questions and answers. Can use HTML
