- ahmad alhayek

 Question 1 The electricity bills of customers are calculated as follows: 10 Marks

1. If 500 units or fewer are used, the cost is 0.02 JD per unit.Otherwise the cost is 10 JD for the first 500 units and 0.05 JD for every unit in excess of 500.
2. A basic service fee of 5 JD is charged for every bill.
i. Write a module called ElectricityCost that takes as an argument a float number represents the consumed electricity units and prints the cost in based on the above 2 rules. (4 marks )
ii. Write a main Module that asks the user to enter values of consumed units and calls the ElectricityCost module to prints the cost of each entered value. (3 marks)
iii. Draw the flow chart for complete program (3 marks)

Expert Answer

  • Deepak Singh's Avatar

    SOLUTION-
    I have solve the problem in C++ code with comments and screenshot for easy understanding :)

    CODE-

    #include<stdio.h>

    float ElectricityCost(float units)
    {
    float bill;
    if(units<500)
    bill = 5 + 0.02*units;
    else
    bill = 15 + 0.05*(units-500);
    return bill;
    }

    int main()
    {
    float units,bill;
    while(true){
    printf("Enter number of units consumed : ");
    scanf("%f",&units);
    if(units<0)
    break;
    bill = ElectricityCost(units);
    printf("Total bill : %f JD\n\n",bill);
    }
    return 0;
    }


    SCREENSHOT-

    Enter number of units consumed : 567 Total bill : 18.350000 JD Enter number of units consumed : 435 Total bill : 13.700000 JD
    IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL SOLVE IT FOR YOU:)
    ----------------PLEASE RATE THE ANSWER-----------THANK YOU!!!!!!!!----------

    Comment 

ليست هناك تعليقات:

إرسال تعليق

ahmad alhayek تصميم ahmad alhayek جميع الحقوق محفوظة 2016

صور المظاهر بواسطة sndr. يتم التشغيل بواسطة Blogger.