Question

C programming help! Write a program that reads the electricity consumption (in kWh) and computes the...

C programming help!

Write a program that reads the electricity consumption (in kWh) and computes the electricity bill based on the following information:

• The first 50 kWh costs 8.5 cents/kWh

• Next 100 kWh costs 9.5 cents/kWh

• Next 100 kWh costs 9.8 cents/kWh

• The consumption above 250 kWh costs 10.25 cents/kWh

Additional surcharge 20% is added to the bill. The input of the program is one integer and the output will be “The total bill is $?.”, where ? is the price of electricity rounded to two decimal places.

Example of input: 303

Corresponding output: The total bill is $34.78.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE IN C:

#include <stdio.h>

int main()
{
int n ;
printf("Enter the electricity consumption(in Kwh) : ");
scanf("%d",&n);
float bill = 0 ;
if(n > 250){
bill += (n-250) * 10.25 ;
n = 250 ;
}
if(n > 150){
bill += (n-150) * 9.8 ;
n = 150 ;
}
if(n > 50){
bill += (n-50) * 9.5 ;
n = 50 ;
}
bill += n * 8.5 ;
bill = bill + bill * 0.2 ;
bill = bill / 100 ;
printf("The total bill is $%.2f",bill);

return 0;
}

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
C programming help! Write a program that reads the electricity consumption (in kWh) and computes the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • java programming language Problem3 (1.5 points). Write a Java program to input electricity unit charges and...

    java programming language Problem3 (1.5 points). Write a Java program to input electricity unit charges and calculate total electricity bill according to the given condition: For first 50 units Rs. 0.50/unit For next 100 units Rs. 0.75/unit For next 100 units Rs. 1.20/unit For unit above 250 Rs. 1.50/unit An additional surcharge of 20% is added to the bill Problem4 (1 points). Write a Java program to inputs weekday number and prints the weekday name using switch.

  • US government website says the following interesting information: In 2017, the average annual electricity consumption for...

    US government website says the following interesting information: In 2017, the average annual electricity consumption for a U.S. residential utility customer was 10,399 kilowatthours (kWh), an average of 867 kWh per month. Louisiana had the highest annual electricity consumption at 14,242 kWh per residential customer, and Hawaii had the lowest at 6,074 kWh per residential customer. Let us compute the electricity usage and the bill for last month by asking a few questions to a homeowner. Here are the input...

  • Problem 4: A machine shop purchases electricity at the following rates: First 100 kWh at 13.0...

    Problem 4: A machine shop purchases electricity at the following rates: First 100 kWh at 13.0 cents per kWh. Next 200 kWh at 11.7 cents per kWh Next 300 kWh at 10.5 cents per kWh. Over 600 kWh at 9.5 cents per kWh. Be accurate to at least two decimal places for all the following problems (a) (3 pts.) The shop uses 392 kWh/month. (a.1) What is the total cost per month (S/month)? (a.2) Average cost (cents/kWh) (a.3) Marginal cost...

  • using C programming Date Write a program that reads a month and a day in that...

    using C programming Date Write a program that reads a month and a day in that month and prints the date in format "month day". The input is two integers, one between 1 and 12 (inclusive) and one between 1 and 31 (inclusive) and the output is a single line in format "month day". For example, for input 2 10 the program will print "February 10th". The day will always have the ordinal indicator, e.g. 1st, 2nd, 3rd, 4th. Example...

  • C programming question! Write a program that reads two numbers and finds the greater one. The...

    C programming question! Write a program that reads two numbers and finds the greater one. The input is two integers and the output will be a single line “The maximum of ? and ? is ?.”, where ? and ? are the input values and ? is the maximum of ? and ?. If ? and ? are equal, ? will be equal to both of them. Example of input: 10 20 Corresponding output: The maximum of 10 and 20...

  • USE C++ Hyde Park Electric Co. bills its customers on the basis of kilowatt hours (KWH)...

    USE C++ Hyde Park Electric Co. bills its customers on the basis of kilowatt hours (KWH) used, as follows: Kilowatt hours (KWH) used​​​Rate 1-100 7 cent per KWH 101-250 RM7.00 + 5 cents * KWH over 100 251-750 RM14.50 + 4 cents * KWH over 250 Over 750​​​​​RM34.50 + 3 cents * KWH over 750 The input will include each customer’s name, Account number and the number of kilowatt hours used (must be a positive value). The output should display...

  • C programming! Write a program that reads integers until 0 and prints the sum of values...

    C programming! Write a program that reads integers until 0 and prints the sum of values on odd positions minus the sum of values on even positions. Let ?1, ?2, … , ??, 0 be the input sequence. Then the program prints the value of ?1 − ?2 + ?3 − ?4 + ⋯ ??. The input is a sequence of integers that always contains at least 0 and the output will be a single number. For example, for input...

  • 1. Write a C++ program that reads sides of a triangle a, b and c from a file and computes the are...

    1. Write a C++ program that reads sides of a triangle a, b and c from a file and computes the area of a triangle and counts total number of areas program has computed Program should have two functions sfun(): sfun receives the values of a, b and c then computes and returns the value ofs as areafun 0: areafun receives the value of s and computes and return the area of a triangle to main program using below formulae...

  • Programming language is C++. 9. Write a program that reads digits and composes them into integers....

    Programming language is C++. 9. Write a program that reads digits and composes them into integers. For example, 123 is read as the characters 1, 2, and 3. The program should output 123 is 1 hundred and 2 tens and 3 ones. The number should be output as an int value Handle numbers with one, two, three, or four digits. Hint: To get the integer value 5 from the character '5' subtract '0' that is, '5'-'0'

  • Java programming 1. Write a program that reads an unspecified number of integers, determines how many...

    Java programming 1. Write a program that reads an unspecified number of integers, determines how many positive and negative value have been read, and computes the total and average of the input values (not counting zeros. Your program ends with the input 0. Display the average as a floating point number Here are sample runs: (red indicates a user input) Enter an integer, the input ends if it is 0: 1 2 -1 3 0 The number of positives is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT