/* File: Kilowatt-hours.c
Calculate and print bills for the city company.*/
#include <stdio.h>
int main()
{
int account_number;
char code;
double bills, kilowatt_hours, peak_hours, off_peak_hours;
printf("Please enter Your account number: \n");
scanf("%d", &account_number);
printf("Enter Your user code [R/C/I]: \n");
printf("R = Residential\n");
printf("C = Commercial\n");
printf("I = Industrial\n");
printf("\nCode = ");
scanf("&c", &code);
do
{
printf("Invalid code!!!\n");
if(code != 'R' && code != 'C' && code != 'I')
{
printf("Please enter your code again: \n");
scanf("%c", &code);
}
}while(code != 'R' && code != 'C' && code != 'I');
if(code == 'R')
{
printf("Please enter number of the kilowatt-hours: ");
scanf("%lf", &kilowatt_hours);
bills = 6.00 + kilowatt_hours*0.045;
printf("Your bills is RM%.2f\n", bills);
}
else if(code == 'C')
{
printf("Please enter number of the kilowatt-hours: ");
scanf("%lf", &kilowatt_hours);
{
if(kilowatt_hours <= 1000.00)
{
bills = 60.00/1000.00*kilowatt_hours;
printf("Your bills is RM%.2f\n", bills);
}
else
{
bills = 60.00 + kilowatt_hours*0.045;
printf("Your bills is RM%.2f\n", bills);
}
}
}
else if(code == 'I')
{
printf("Enter the number for the peak hours: \n");
scanf("%lf", &peak_hours);
{
if(peak_hours <= 1000.00)
{
peak_hours = 76.00/1000*peak_hours;
}
else
{
peak_hours = 76.00 + peak_hours*0.065;
}
}
printf("Enter the number for the off peak hours: \n");
scanf("lf", &off_peak_hours);
{
if(off_peak_hours <= 1000.00)
{
off_peak_hours = 40.00/1000*off_peak_hours;
}
else
{
off_peak_hours = 40.00 + off_peak_hours*0.028;
}
}
bills = peak_hours + off_peak_hours;
printf("Your bills is RM%.2f", bills);
}
return 0;
}
hket89 0 Light Poster
Recommended Answers
Jump to PostPlease post your question.
Please use English which every one can understand.
What is vf?
Jump to PostIts ok hket89, our point is use the english whatever you know, don't make it like SMS language, even if you are not understandable it is OK, but don't use SMS like language.
Now, if you dont have question just mark this thread as solved, so that people will stop …
All 7 Replies
hket89 0 Light Poster
DangerDev 107 Posting Pro in Training
9868 35 Light Poster
hket89 0 Light Poster
yellowSnow 607 Posting Whiz in Training
hket89 0 Light Poster
DangerDev 107 Posting Pro in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.