Thread: Having trouble with counters

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    40

    Having trouble with counters

    Hello, I am having trouble with getting my counters to work to count how many credit transactions and debit transactions there are.. UNless there is another way I can count them.. Could someone help me please...
    Last edited by tameeyore; 10-07-2004 at 07:05 PM.

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    For the love of jeebus use code tags!

    (Look at the top of the forum to find out how)
    Last edited by XSquared; 10-07-2004 at 06:42 PM.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    use code tags...try again

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    40

    Sorry new at this..

    I am not sure how the code tags work.. Sorry I am new at this... I read abt them and did what it said unless I am not getting.. Sorry if this is wrong again...


    Code:
     
    #include <stdio.h>
    #include <math.h>
    
    #define strt_blnce 2000.00
    #define yrly_intrst .02
    
    int main (int argc, char **argv){
    
    
    float dpst, withdrw, withdrw2, blnce, crdt, dbt, intrst,
    finalblnce,blnce2;
    int date, opt;
    
    printf("Your current balance is $%1.2f \n", strt_blnce);
    
    printf("Banking program \n");
    printf("1.) Deposit funds (credit transaction) \n");
    printf("2.) Withdraw funds (debit transaction) \n");
    printf("3.) Print statement of the acct \n");
    printf("4.) Compute interest and exit program \n");
    printf("Please indicate you option: ");
    scanf("%d",&opt);
    
    
    switch(opt){
    case 1:
    crdt++;
    printf("Please enter a valid date from 1 to 31: ");
    scanf("%d", &date);
    printf("How much do you want to deposit? ");
    scanf("%f", &dpst);
    blnce = strt_blnce + dpst;
    printf("Your current balance is $%1.2f. \n", blnce);
    printf("Please indicate your option: ");
    scanf("%d", &opt);
    
    
    case 2:
    printf("Please enter a valid date from 1 to 31: ");
    scanf("%d", &date);
    printf("How much do you want to withdraw? ");
    scanf("%f", &withdrw);
    if (withdrw > blnce) {
    printf("Please enter a smaller amt. \n");
    printf("How much do you want to withdraw? ");
    scanf("%f", &withdrw);
    }else
    blnce2 = blnce - withdrw;
    printf("Your current balance is $%1.2f. \n", blnce2);
    dbt++;
    printf("Please indicate your option: ");
    scanf("%d", &opt);
    
    case 3:
    printf("Please enter a valid date from 1 to 31: ");
    scanf("%d", &date);
    printf("Your current balance is $%1.2f. \n", blnce);
    printf("Number of credit transactions: %d \n ", crdt);
    printf("Number of debit trasactions: %d \n ", dbt );
    printf("Please indicate your option: ");
    scanf("%d", &opt);
    
    case 4:
    printf("Statement of Account for October, 2004 \n");
    printf("Number of credit transactions: %.2d \n ", crdt);
    printf("Number of debit transactions: %.2d \n ", dbt);
    intrst = blnce * yrly_intrst * 12;
    printf("Interest computed: $%1.2f \n", intrst);
    finalblnce = blnce + intrst;
    printf("Good Bye!! \n");
    
    }
    
    
    
    
    return 0;
    
    }

  5. #5
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    Indentation...

    Code:
    #include <stdio.h>
    #include <math.h>
    
    #define strt_blnce 2000.00
    #define yrly_intrst .02
    
    int main(int argc, char **argv)
    {
    
        float dpst, withdrw, withdrw2, blnce, crdt, dbt, intrst,
            finalblnce, blnce2;
        int date, opt;
    
        printf("Your current balance is $%1.2f \n", strt_blnce);
    
        printf("Banking program \n");
        printf("1.) Deposit funds (credit transaction) \n");
        printf("2.) Withdraw funds (debit transaction) \n");
        printf("3.) Print statement of the acct \n");
        printf("4.) Compute interest and exit program \n");
        printf("Please indicate you option: ");
        scanf("%d", &opt);
    
    
        switch (opt) {
        case 1:
            crdt++;
            printf("Please enter a valid date from 1 to 31: ");
            scanf("%d", &date);
            printf("How much do you want to deposit? ");
            scanf("%f", &dpst);
            blnce = strt_blnce + dpst;
            printf("Your current balance is $%1.2f. \n", blnce);
            printf("Please indicate your option: ");
            scanf("%d", &opt);
    
    
        case 2:
            printf("Please enter a valid date from 1 to 31: ");
            scanf("%d", &date);
            printf("How much do you want to withdraw? ");
            scanf("%f", &withdrw);
            if (withdrw > blnce) {
                printf("Please enter a smaller amt. \n");
                printf("How much do you want to withdraw? ");
                scanf("%f", &withdrw);
            } else
                blnce2 = blnce - withdrw;
            printf("Your current balance is $%1.2f. \n", blnce2);
            dbt++;
            printf("Please indicate your option: ");
            scanf("%d", &opt);
        case 3:
            printf("Please enter a valid date from 1 to 31: ");
            scanf("%d", &date);
            printf("Your current balance is $%1.2f. \n", blnce);
            printf("Number of credit transactions: %d \n ", crdt);
            printf("Number of debit trasactions: %d \n ", dbt);
            printf("Please indicate your option: ");
            scanf("%d", &opt);
    
        case 4:
            printf("Statement of Account for October, 2004 \n");
            printf("Number of credit transactions: %.2d \n ", crdt);
            printf("Number of debit transactions: %.2d \n ", dbt);
            intrst = blnce * yrly_intrst * 12;
            printf("Interest computed: $%1.2f \n", intrst);
            finalblnce = blnce + intrst;
            printf("Good Bye!! \n");
    
        }
    
        return 0;
    }

  6. #6
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    are you a damn idiot?...you're the kind of person who would convert real player .ram files into mpeg's and wonder why they still sound so I am sillyI am sillyI am sillyI am sillyty.

  7. #7
    Registered User
    Join Date
    Sep 2004
    Posts
    40
    No I am not an idiot... I am just more hardware than programming.. So this is not as easy as if I had to deal with servers, hubs, routers.. So sorry if it seems like I am an idiot.. But I am not and I don't appreciate being called one...

  8. #8
    Registered User
    Join Date
    Sep 2004
    Posts
    40
    Hope this is better


    Code:
    #include <stdio.h>
    #include <math.h>
    
    #define strt_blnce 2000.00
    #define yrly_intrst .02
    
    int main(int argc, char **argv)
    {
    
        float dpst, withdrw, withdrw2, blnce, crdt, dbt, intrst,
            finalblnce, blnce2;
        int date, opt;
    
        printf("Your current balance is $%1.2f \n", strt_blnce);
    
        printf("Banking program \n");
        printf("1.) Deposit funds (credit transaction) \n");
        printf("2.) Withdraw funds (debit transaction) \n");
        printf("3.) Print statement of the acct \n");
        printf("4.) Compute interest and exit program \n");
        printf("Please indicate you option: ");
        scanf("%d", &opt);
    
    
        switch (opt) {
        case 1:
            crdt++;
            printf("Please enter a valid date from 1 to 31: ");
            scanf("%d", &date);
            printf("How much do you want to deposit? ");
            scanf("%f", &dpst);
            blnce = strt_blnce + dpst;
            printf("Your current balance is $%1.2f. \n", blnce);
            printf("Please indicate your option: ");
            scanf("%d", &opt);
    
    
        case 2:
            printf("Please enter a valid date from 1 to 31: ");
            scanf("%d", &date);
            printf("How much do you want to withdraw? ");
            scanf("%f", &withdrw);
            if (withdrw > blnce) {
                printf("Please enter a smaller amt. \n");
                printf("How much do you want to withdraw? ");
                scanf("%f", &withdrw);
            } else
                blnce2 = blnce - withdrw;
            printf("Your current balance is $%1.2f. \n", blnce2);
            dbt++;
            printf("Please indicate your option: ");
            scanf("%d", &opt);
        case 3:
            printf("Please enter a valid date from 1 to 31: ");
            scanf("%d", &date);
            printf("Your current balance is $%1.2f. \n", blnce);
            printf("Number of credit transactions: %d \n ", crdt);
            printf("Number of debit trasactions: %d \n ", dbt);
            printf("Please indicate your option: ");
            scanf("%d", &opt);
    
        case 4:
            printf("Statement of Account for October, 2004 \n");
            printf("Number of credit transactions: %.2d \n ", crdt);
            printf("Number of debit transactions: %.2d \n ", dbt);
            intrst = blnce * yrly_intrst * 12;
            printf("Interest computed: $%1.2f \n", intrst);
            finalblnce = blnce + intrst;
            printf("Good Bye!! \n");
    
        }
    
        return 0;
    }

  9. #9
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    is that your entire program or did you cut it down?....it seems to me you need a loop....

  10. #10
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    Why do the variables crdt and dbt need to be type float? When you use them to display your report, you are specifying an integer, and passing a type float value to printf(). Also, you might want to initialise crdt and dbt to zero before you use them. Do you really need to use the <math.h> header?

    ~/

  11. #11
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Ya know I just saw this bank program in another thread. Must be a standard homework assignment somewhere.

  12. #12
    Registered User
    Join Date
    Sep 2004
    Posts
    40
    This is the entire program

  13. #13
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    move printf accordingly after seeing output (ex: "Banking Program" should probably be outside of loop that i added)
    Code:
    #include <stdio.h>
    #include <math.h>
    
    #define strt_blnce 2000.00
    #define yrly_intrst .02
    
    int main(int argc, char **argv)
    {
    
        float dpst, withdrw, withdrw2, blnce, crdt, dbt, intrst,
            finalblnce, blnce2;
        int date, opt = -1;
    
        //YOU SHOULD INDENT EVERYTHING INSIDE THIS LOOP
        //BUT I'M NOT GOING TO
      
         while(opt != 4){
    
        printf("Your current balance is $%1.2f \n", strt_blnce);
    
        printf("Banking program \n");
        printf("1.) Deposit funds (credit transaction) \n");
        printf("2.) Withdraw funds (debit transaction) \n");
        printf("3.) Print statement of the acct \n");
        printf("4.) Compute interest and exit program \n");
        printf("Please indicate you option: ");
        scanf("%d", &opt);
    
    
        switch (opt) {
        case 1:
            crdt++;
            printf("Please enter a valid date from 1 to 31: ");
            scanf("%d", &date);
            printf("How much do you want to deposit? ");
            scanf("%f", &dpst);
            blnce = strt_blnce + dpst;
            printf("Your current balance is $%1.2f. \n", blnce);
            printf("Please indicate your option: ");
            scanf("%d", &opt);
    
    
        case 2:
            printf("Please enter a valid date from 1 to 31: ");
            scanf("%d", &date);
            printf("How much do you want to withdraw? ");
            scanf("%f", &withdrw);
            if (withdrw > blnce) {
                printf("Please enter a smaller amt. \n");
                printf("How much do you want to withdraw? ");
                scanf("%f", &withdrw);
            } else
                blnce2 = blnce - withdrw;
            printf("Your current balance is $%1.2f. \n", blnce2);
            dbt++;
            printf("Please indicate your option: ");
            scanf("%d", &opt);
        case 3:
            printf("Please enter a valid date from 1 to 31: ");
            scanf("%d", &date);
            printf("Your current balance is $%1.2f. \n", blnce);
            printf("Number of credit transactions: %d \n ", crdt);
            printf("Number of debit trasactions: %d \n ", dbt);
            printf("Please indicate your option: ");
            scanf("%d", &opt);
    
        case 4:
            printf("Statement of Account for October, 2004 \n");
            printf("Number of credit transactions: %.2d \n ", crdt);
            printf("Number of debit transactions: %.2d \n ", dbt);
            intrst = blnce * yrly_intrst * 12;
            printf("Interest computed: $%1.2f \n", intrst);
            finalblnce = blnce + intrst;
            printf("Good Bye!! \n");
    
        }
    
    
       }//END LOOP
    
        return 0;
    }

  14. #14
    Registered User
    Join Date
    Sep 2004
    Posts
    40
    What thread did you see a similar program on?

  15. #15
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    oh oh oh oh.....

    make sure you dbt = 0 before using dbt++;....
    if you don't do that dbt's value is the value of whatever was in that spot in memory before



    make sure you initialize any variable you use for a counter...
    saying
    int count;
    does not necessarily mean count will be zero
    Last edited by misplaced; 10-07-2004 at 07:19 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble with assignment in C
    By mohanlon in forum C Programming
    Replies: 17
    Last Post: 06-23-2009, 10:44 AM
  2. Replies: 6
    Last Post: 01-03-2007, 03:02 PM
  3. [C] Best way to save matrix counters
    By Nazgulled in forum C Programming
    Replies: 7
    Last Post: 03-24-2006, 05:02 PM
  4. Is it so trouble?
    By Yumin in forum Tech Board
    Replies: 4
    Last Post: 01-30-2006, 04:10 PM
  5. trouble scanning in... and link listing
    By panfilero in forum C Programming
    Replies: 14
    Last Post: 11-21-2005, 12:58 PM