this program is all about computing the bill of the electricity/.// the first 150kilowatts will be 10.00php... then additional kilowats will be add for another 20.00 per kilowatts...
In their bill also, there will be additional 5% for the tax...

And My prof give this condition in doing the program:
1.the first function should compute the amount w/o tax.
2. the secong will function computing the first function and with the tax.

thank you in advance whosoever heLp me in this...

problem: this source code is working.. but the thing is it does not give the accurate answer.

ASSIGNME.CPP

Attachments
``````#include<stdio.h>
#include<conio.h>
#include<math.h>

float compute_amount(int kilowatt);
float compute_tax(float total);

void main()
{clrscr();
int kilowatt;
float Amount;
char decide;
do{
scanf("%d",&kilowatt);
Amount=compute_amount(kilowatt);
printf("Your current Bill for this month is: %f\n\n",Amount);
printf("Do you want to repeat your transaction[Y or N]:  ");
scanf("\n");
scanf("%c",&decide);
}
while(decide=='y'||decide=='Y');
getch();
}

float compute_amount(int kilowatt)
{float total;

total=(kilowatt-15)*20+(10)+compute_tax(total);
}

float compute_tax(float total)
{float totalwtax,tax=0.05;

totalwtax=total+tax;

}``````
3
Contributors
7
Replies
8
Views
9 Years
Discussion Span
Last Post by geemicah

Why didn't you just post the code?..

``````#include<stdio.h>
#include<conio.h>
#include<math.h>

float compute_amount(int kilowatt);
float compute_tax(float total);

void main()
{clrscr();
int kilowatt;
float Amount;
char decide;
do{
scanf("%d",&kilowatt);
Amount=compute_amount(kilowatt);
printf("Your current Bill for this month is: %f\n\n",Amount);
printf("Do you want to repeat your transaction[Y or N]:  ");
scanf("\n");
scanf("%c",&decide);
}
while(decide=='y'||decide=='Y');
getch();
}

float compute_amount(int kilowatt)
{float total;

total=(kilowatt-15)*20+(10)+compute_tax(total);
}

float compute_tax(float total)
{float totalwtax,tax=0.05;

totalwtax=total+tax;

}``````

Now to fix it up a little.. Ive indented the code, added spaces where appropriate, and made main return an int.

``````#include <stdio.h>
#include <conio.h>
#include <math.h>

float compute_amount(int kilowatt);
float compute_tax(float total);

int main() {
clrscr();
int kilowatt;
float Amount;
char decide;
do {
scanf("%d",&kilowatt);
Amount = compute_amount(kilowatt);
printf("Your current Bill for this month is: %f\n\n",Amount);
printf("Do you want to repeat your transaction[Y or N]:  ");
scanf("\n");
scanf("%c", &decide);
} while (decide=='y'||decide=='Y');
getch();
return 0;
}

float compute_amount(int kilowatt) {
float total;
total = (kilowatt - 15) * 20 + 10 + compute_tax(total);
}

float compute_tax(float total) {
float totalwtax, tax = 0.05;
totalwtax = total + tax;
}``````

One problem. `scanf("%d",&kilowatt);` kilowatt isn't an integer. Change the format specifier to what you'd use for a float.

Is this right? `(kilowatt-15)*20+(10)+compute_tax(total);` Haven't looked at it, just seems odd that you're taking 15 from kW.

Is this right? `totalwtax=total+tax;` Should it be * not +?

yahoOOOOOoooooooooOoooooooo.... Its working... i now it gives A accurate Answer!!! thank you very much!!thank you for your help!!! now, I can send this to my Prof.. GodbLEss ^_^

its working... but it does not including the tax??

its working but the output or the results does not including the Tax... hhmmm?? ^_T

I'd imagine you should change:

``total = (kilowatt - 15) * 20 + 10 + compute_tax(total);``

to

``````total = (kilowatt - 15) * 20 + 10;
total += compute_tax(total);``````

, but again check your formulae are correct.

hhm..
yeah.. now, it gives me accurate answer!!! thank you very much!!!!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.