0% found this document useful (0 votes)
61 views8 pages

Home Exam (2) Ex:1

The document contains code for calculating electricity bills under old and new tariff rates. It takes user input for KWH consumed (x) and calculates the bill under old rates by applying different rates depending on consumption. It similarly calculates the bill under new rates (y) and then calculates the percentage difference between the two bills. It provides sample outputs for different consumption values, displaying the calculated bills and percentage difference each time.

Uploaded by

ĦøÐâ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views8 pages

Home Exam (2) Ex:1

The document contains code for calculating electricity bills under old and new tariff rates. It takes user input for KWH consumed (x) and calculates the bill under old rates by applying different rates depending on consumption. It similarly calculates the bill under new rates (y) and then calculates the percentage difference between the two bills. It provides sample outputs for different consumption values, displaying the calculated bills and percentage difference each time.

Uploaded by

ĦøÐâ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Home Exam (2) Ex :1

clear all

close all

clc

% (X)=(PT/KWH)(Old Tariff)

x=input('plz Enter x :');

% (y)=(PT/KWH) (new Tariff)

y=input('plz Enter y :');

% Bill of Old Tariff(K.W.H/Month)

if x<=100

charge1=30*x;

elseif x<=250

charge1=(44*x);

elseif x>=251 & x<=600

charge1=(44*250)+(59*(x-250));

elseif x>=601 & x<=1000

charge1=(59*(600))+(78*(x-600));

else x>1000

charge1=83*x;

end

c1=(charge1/100)

% Bill of New Tariff(K.W.H/Month)

if y<=100

charge2=35*y;

elseif y<=250
charge2=69*y;

elseif y>=251 & y<=600

charge2=(69*(250))+(69*(y-250));

elseif y>=601 & y<=1000

charge2=(69*600)+(96*(y-600));

else y>1000

charge1=(1000*78)+83*(x-1000);
end

c2=(charge2/100)

% Percentage Between The Old And The New

percentage=(c1/c2)*100

Answer (Ex : 1)
plz Enter x :177

plz Enter y :177

c1 77.8800

c2 =122.1300

percentage = 63.7681

plz Enter x :50


plz Enter y :50

c1 =15

c2 = 17.5000

percentage =85.7143

plz Enter x :250

plz Enter y :250

c1 =110

c2 =172.5000

percentage = 63.7681

plz Enter x :300

plz Enter y :300

c1 =139.5000

c2 =207

percentage =67.3913

plz Enter x :700

plz Enter y :700

c1 = 432

c2 =510

percentage =84.7059

plz Enter x :1200

plz Enter y :1200

c1 =946

c2 = 1152

percentage = 82.1181
Home Exam (2)
clear all

close all

clc

% (X)=K.W.H/Month (Old Charge)

x=input('plz Enter x :');

% (y)=K.W.H/Month (new Charge)

y=input('plz Enter y :');

% Bill oF Old Charge

if x<=50

Charge1=7.5*x;

elseif x>=51 & x<=100

Charge1=(50*7.5)+(14.5*(x-50));

elseif x<=200

Charge1=x*16;
elseif x>=201 & x<=350

Charge1=(16*200)+(35*(x-200));

elseif x>=351 & x<=600

Charge1=(35*350)+(44*(x-350));

elseif x>=651 & x<=1000

Charge1=(44*600)+(71*(x-600));

else x>1000

Charge1=81*x;

end

c1=(Charge1/100)

% Bill oF New Charge

if x<=50

Charge2=11*y;

elseif y>=51 & y<=100

Charge2=(50*11)+(19*(y-50));

elseif y<=200

Charge2=y*21;

elseif y>=201 & y<=350

Charge2=(21*200)+(42*(y-200));

elseif y>=351 & y<=600

Charge2=(42*350)+(55*(y-350));

elseif y>=651 & y<=1000

Charge2=(55*600)+(95*(y-600));

else y>1000

Charge2=(1000*95)+95*(y-1000);
end

c2=(Charge2/100)
% Percentage Between The Old And The New

percentage=(c1/c2)*100

Answer (EX:2)
plz Enter x :177

plz Enter y :177

c1 =28.3200

c2 = 37.1700

percentage = 76.1905

plz Enter x :50

plz Enter y :50

c1 =3.7500

c2 =5.5000

percentage =68.1818

plz Enter x :250

plz Enter y :250

c1 = 49.5000

c2 =63

percentage =78.5714

plz Enter x :300

plz Enter y :300

c1 =67

c2 = 84

percentage =79.7619
plz Enter x :1200

plz Enter y :1200

c1 = 872

c2 = 1140

percentage = 76.4912
Name : Hady Mohamed Abd El_Aty
Sec : 7
To : Dr.Ahmed El_Rifai

You might also like