🔒 Closed Electric Bill calculator using functions

Status
Not open for further replies.

Block_MC

Honorary Poster
Mga boss pa help naman jan AHHAHA bumigay na utak ko sa kaka debug. Pano ba mag lagay ng functions?
BSIT freshman here
INSTRUCTIONS
[Task Should be Separated into Functions]
+1st Function Determine the Charge/Unit.
+2nd Function - Calculate Unit Charge.
+3rd Function - Calculate Surcharge.
+4th Function - Calculate Total Customer Bill

Eto code ko

#include <stdio.h>

int main() {
int custid, con;
float charge, suprchg = 0, unit, total;

printf("Input Customer ID: ");
scanf("%d", & custid);
printf("Input the unit consumed by the customer: P ");
scanf("%d", & con);

if (con < 200)
charge = 1.50;
else if (con >= 250 && con < 400)
charge = 1.60;
else if (con >= 450 && con < 600)
charge = 1.85;
else
charge = 2.00;
unit = con * charge;
if (unit > 400)
suprchg = unit * 10 / 100.0;
total = unit + suprchg;
if (total < 100)
total = 100;

printf("\n[Electricity Bill]\n");
printf("Customer ID# : %d\n", custid);
printf("Unit Consumed : P %d\n", con);
printf("Amount Charges @P%.2f per unit : P %.2f\n", charge, unit);
printf("Surchage Amount : P %.2f\n", suprchg);
printf("Total Customer Bill : P %.2f\n", total);

return 0;
}


ps. Sensya na kung ang pangit ko mag name ng variables HAHAHAHHAH
 
look for resource online..madami ka mahahanap na mga examples...
Ex:
Code:
double getTotal(int con){
     double total=0.0;
    //perform operations here
    return total;
}
 
look for resource online..madami ka mahahanap na mga examples...
Ex:
Code:
double getTotal(int con){
     double total=0.0;
    //perform operations here
    return total;
}
look for resource online..madami ka mahahanap na mga examples...
Ex:
Code:
double getTotal(int con){
     double total=0.0;
    //perform operations here
    return total;
}
Kaya nga eh HAHHAHA actually been seaching na din pero wala akong mahanap
 
try mo yung example ko...
Code:
#include
//function def
double getTotal(int con);
int main(){
  .
  .
  .
  //get input etc
  ///cal function
  total = getTotal(con);
  printf()

}
//function
double getTotal(int con){
  double total=0.0;
  //perform logic here ex. if..else
  //perform computation
  total =....;
  //return result
   return total;
}
 
Tama yung example ni vin le. Ieexpand ko lang, parang ganito yung mangyayari


#include <stdio.h>

int main()
{
int custid;
float con, charge(float), unit(float), surcharge(float), total(float);

printf("Input Customer ID: ");
scanf("%d", &custid);
printf("Input the unit consumed by the customer: P ");
scanf("%f", &con);

printf("\n[Electricity Bill]\n");
printf("Customer ID# : %d\n", custid);
printf("Unit Consumed : P %f\n", con);

printf("Amount Charges @P %.2f per unit : P %.2f\n", charge(con), unit(con));
printf("Surchage Amount : P %.2f\n", surcharge(con));
printf("Total Customer Bill : P %.2f\n", total(con));

return 0;
}

float charge(float con)
{
if (con < 200)
{
return 1.50;
}
else if (con >= 250 && con < 400)
{
return 1.60;
}
else if (con >= 450 && con < 600)
{
return 1.85;
}
return 2.00;
}

float unit(float con)
{
return con * (charge(con));
}

float surcharge(float con)
{
return unit(con) * 10 / 100;
}

float total(float con)
{
return unit(con) + surcharge(con);
}
 
Tama yung example ni vin le. Ieexpand ko lang, parang ganito yung mangyayari


#include <stdio.h>

int main()
{
int custid;
float con, charge(float), unit(float), surcharge(float), total(float);

printf("Input Customer ID: ");
scanf("%d", &custid);
printf("Input the unit consumed by the customer: P ");
scanf("%f", &con);

printf("\n[Electricity Bill]\n");
printf("Customer ID# : %d\n", custid);
printf("Unit Consumed : P %f\n", con);

printf("Amount Charges @P %.2f per unit : P %.2f\n", charge(con), unit(con));
printf("Surchage Amount : P %.2f\n", surcharge(con));
printf("Total Customer Bill : P %.2f\n", total(con));

return 0;
}

float charge(float con)
{
if (con < 200)
{
return 1.50;
}
else if (con >= 250 && con < 400)
{
return 1.60;
}
else if (con >= 450 && con < 600)
{
return 1.85;
}
return 2.00;
}

float unit(float con)
{
return con * (charge(con));
}

float surcharge(float con)
{
return unit(con) * 10 / 100;
}

float total(float con)
{
return unit(con) + surcharge(con);
}
ooow ganto lang pala, thank you paps! u da best labyu no homo HAHAHHA
 
Kuys Aoshinomori alam mo ba to?
patulong pano lagyan ng array for usernames and pass tas for loop para ma access them?
1648627720078.webp

Eto Code ko

#include <stdio.h>
#include <string.h>

int main()
{
char username[2];
char password[3];

printf("Enter your username:\n");
scanf("%s",&username);

printf("Enter your password:\n");
scanf("%s",&password);

if(strcmp(username,"bogart")==0){
if(strcmp(password,"123")==0){

printf("\nLogin Success! Welcome sayu l0ds.");
}else
{
printf("\nWrong password krazy.");
}
}else
{
printf("\nUser doesn't exist");
}
return 0;
}
 
Status
Not open for further replies.

About this Thread

  • 7
    Replies
  • 903
    Views
  • 3
    Participants
Last reply from:
Aoshinomori

Trending Topics

Online now

Members online
965
Guests online
1,332
Total visitors
2,297

Forum statistics

Threads
2,273,376
Posts
28,949,064
Members
1,235,719
Latest member
Wzpprince
Back
Top