Answer to Question #243652 in C++ for xtian

Question #243652
Write a program that will calculate and show bills of the Electric Company. The rates vary depending on whether the use is residential (R), commercial( C) , or industrial (I). Any other code should be treated as an error.
The program should accept the subscriber ID, Subscriber Name, his total electrical consumption in a month, and the code of the consumer type.

The rates are computed as follows:

R: 50 plus .50 per kwh used
C: 100 for the first 1000 kwh and 0.45 for each additional kwh
I: 180 for the first 1000 kwh and 0.75 for each additional kwh


please use ,
#include<stdio.h>
#include<conio.h>

and,
scanf:
printf
1
Expert's answer
2021-09-28T07:29:20-0400
#include <stdio.h>
#include <conio.h>


int main() {
    int id;
    char name[80];
    double totConsump;
    char code;
    double bills;


    printf("Enter an ID of a subscriber: ");
    scanf("%d", &id);
    printf("Enter a name of the subscriber: ");
    scanf("%s", name);
    printf("Enter total electrical consumption in a month: ");
    scanf("%lf", &totConsump);
    printf("Enter a code of the consumer type: ");
    code = getch();

    if (code == 'R') {
        bills = 50 + 0.50*totConsump;
    }
    else if (code == 'C') {
        bills = 100;
        if (totConsump > 1000) {
            bills += 0.45*(totConsump - 1000);
        }
    }
    else if (code == 'I') {
        bills = 180;
        if (totConsump > 1000) {
            bills += 0.75*(totConsump - 1000);
        }
    }
    else {
        printf("Incorrect code: %c\n", code);
        return 1;
    }
    printf("\n\n===========================\nElectric Company\n");
    printf("Bill for %s  ID: %06d\n", name, id);
    printf("Total month consumption %.1f kwh; Total cost $%.2f\n",
           totConsump, bills);

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS