ব্যবহারকারীর খরচ করা ইউনিটের ভিত্তিতে বিদ্যুৎ বিল জেনারেট করা হয়। যদি ইউনিট বেশি হয়, তবে প্রতি ইউনিট চার্জের রেটও বাড়ে।
ন্যূনতম ইউনিট খরচ হলে লজিক—
if (units < 50) {
amt = units * 3.50;
unitcharg = 25;
}
ইউনিট ৫০ থেকে ১০০ এর মধ্যে হলে লজিক—
else if (units <= 100) {
amt = 130 + ((units - 50) * 4.25);
unitcharg = 35;
}
ইউনিট ১০০ থেকে ২০০ এর মধ্যে হলে লজিক—
else if (units <= 200) {
amt = 130 + 162.50 + ((units - 100) * 5.26);
unitcharg = 45;
}
ইউনিট ২০০-এর বেশি হলে লজিক—
amt = 130 + 162.50 + 526 + ((units - 200) * 7.75); unitcharg = 55;
অতএব, ফাইনাল অ্যামাউন্ট হবে—
total = amt + unitcharg;
উদাহরণ
বিদ্যুৎ বিল জেনারেট করার C প্রোগ্রাম—
#include <stdio.h>
int main() {
int units;
float amt, unitcharg, total;
printf(" Enter no of units consumed : ");
scanf("%d", &units);
if (units < 50) {
amt = units * 3.50;
unitcharg = 25;
} else if (units <= 100) {
amt = 130 + ((units - 50) * 4.25);
unitcharg = 35;
} else if (units <= 200) {
amt = 130 + 162.50 + ((units - 100) * 5.26);
unitcharg = 45;
} else {
amt = 130 + 162.50 + 526 + ((units - 200) * 7.75);
unitcharg = 55;
}
total = amt + unitcharg;
printf("electricity bill = %.2f", total);
return 0;
}
আউটপুট
Enter no of units consumed: 280 electricity bill = 1493.50