problems how to carry out the remaining balance

This is a discussion on problems how to carry out the remaining balance within the C Programming forums, part of the General Programming Boards category; hi... i had a problem with a program which starts like this if i input a 100 and input another ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    32

    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

    please help me with this........ please please please

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,543
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    32
    int a,b;
    char ans;

    p("Enter current balance : P ");
    s("%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. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,543
    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?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    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. #6
    Registered User
    Join Date
    Jan 2008
    Posts
    32
    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?

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,543
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by omarbags View Post
    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. #9
    Registered User
    Join Date
    Jan 2008
    Posts
    32
    huhuhu that is why im here to learn from you guys
    it is the lack of knowledge which leads me to some mistakes
    please someone help me T_T

  10. #10
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    >please someone help me T_T
    Ask specific questions.

  11. #11
    Registered User
    Join Date
    Jan 2008
    Posts
    32
    [quote]int bal,ded;
    Code:
    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?
    [/qoute]

  12. #12
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Code:
    int bal,ded;
    char ans;
    
    printf("Enter current balance : P ");
    scanf("%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. #13
    Registered User
    Join Date
    Jan 2008
    Posts
    32
    WHAT THE F***

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

    WAHAHAHAHAHAHA


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

    MWAAAAAAAAAAAAAAAAAAAAAAAAH.....!


    thnx dude your the besttt


    yahooooooooooooooooooo

  14. #14
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    wow that was easy...

  15. #15
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Sigh, tisk tisk robwhit -- don't feed the seagulls. Give them one chip and they want more

    Seriously omarbags, do your own homework. You're the one who'll fail the exam for not knowing C, not us. Get a book, learn C!

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with runtime error
    By azrael in forum C Programming
    Replies: 13
    Last Post: 03-20-2009, 04:53 PM
  2. 20q game problems
    By Nexus-ZERO in forum C Programming
    Replies: 24
    Last Post: 12-17-2008, 04:48 PM
  3. hi need help with credit limit program
    By vaio256 in forum C++ Programming
    Replies: 4
    Last Post: 03-31-2003, 11:23 PM
  4. I need help badly
    By taz_jiggy in forum C++ Programming
    Replies: 4
    Last Post: 04-23-2002, 09:36 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 03:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21