# Thread: problems how to carry out the remaining balance

1. ## problems how to carry out the remaining balance

hi...

i had a problem with a program which starts like this

if i input a 100

and input another which is deducted from it for example 10

so the remaining balance is 90 to be exact

and then i will prompt it to continue the process (y/n)

if i input y=yes

it will carry on the remaining balance which is 90

my program will just return the same number which is 100

2. Use the same variable all the time!
Let's say variable name is X.
Input value into X.
Input value to deduct, deduct from X.
Loop.
Easy.

3. int a,b;
char ans;

p("Enter current balance : P ");
s("&#37;d",&a);

start:

p("Enter amount to deduct: P ");
s("%d",&b);
p("The remaining balance is P %d.\n",a-b;
p("Do another transaction?(y/n)");
s(" %c",&ans);
if(ans=='y')

goto start;

that's my problem..how to loop it

it should return 90 instead of 100

and the process will continue until 100 becomes 0 or i will input n=no

4. Use a loop, give proper names to variables, don't use goto, use code tags, and don't define your own language - use proper function syntax as printf and scanf.
But sheesh, you really have no idea how to subtract something from a variable?

5. You can't just compute the value of a-b, you have to put it somewhere, preferably in the variable you're thinking of as "balance". Had you called your variables something other than "a" or "b", you would know which one that was.

Your loop as you have it "works", for a given value of "works", in that it does exactly what you require it to do. I have no idea what you're complaining about, exactly, although why you don't use a loop structure (of which C has three to choose from) rather than making your own with a goto mystifies me.

PS: I would be willing to bet that this is the last helpful response you will get here until you (1) post your actual code (2) inside code tags with (3) proper, or at least reasonable, indentation.

6. int bal,ded;
char ans;

Code:
```printf("Enter current balance : P ");
scanf("&#37;d",&bal);

do{
printf("Enter amount to deduct: P ");
scanf("%d",&ded);
printf("The remaining balance is P %d.\n",bal-ded;
printf("Do another transaction?(y/n)");
scanf(" %c",&ans);
}
while(ans!='y');```

is this the right one?

7. Even better, learn C. Grab a book or use tutorials or go to a class or whatever. Subtracting from variables and other stuff is the basics of basics.

8. Originally Posted by omarbags
int bal,ded;
char ans;

Code:
```printf("Enter current balance : P ");
scanf("%d",&bal);

do{
printf("Enter amount to deduct: P ");
scanf("%d",&ded);
printf("The remaining balance is P %d.\n",bal-ded;
printf("Do another transaction?(y/n)");
scanf(" %c",&ans);
}
while(ans!='y');```

is this the right one?
Things are looking a little better, in that you read half. You subtract bal-ded, but you still need to put the answer somewhere if you want to keep hold of it. You do know how to assign a value to a variable?

You also need to look again at the difference between == and !=.

9. huhuhu that is why im here to learn from you guys
it is the lack of knowledge which leads me to some mistakes

10. >please someone help me T_T

11. [quote]int bal,ded;
Code:
```char ans;

Code:

printf("Enter current balance : P ");
scanf("&#37;d",&bal);

do{
printf("Enter amount to deduct: P ");
scanf("%d",&ded);
printf("The remaining balance is P %d.\n",bal-ded;
printf("Do another transaction?(y/n)");
scanf(" %c",&ans);
}
while(ans!='y');

is this the right one?```
[/qoute]

12. Code:
```int bal,ded;
char ans;

printf("Enter current balance : P ");
scanf("&#37;d",&bal);

do{
printf("Enter amount to deduct: P ");
scanf("%d",&ded);
bal = bal - ded;
printf("The remaining balance is P %d.\n",bal);
printf("Do another transaction?(y/n)");
scanf(" %c",&ans);
}
while(ans!='y');```

13. WHAT THE F***

HOW THE HELL DID YOU FIGURE IT OUT????

WAHAHAHAHAHAHA

THANK YOU SOOOOOOOOOOOOOOOOOOOOOOOOOOOO MUCHHHHHHHHHH.............!!!

MWAAAAAAAAAAAAAAAAAAAAAAAAH.....!