Thread: Please help

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    96

    Please help

    when i choice the option deposit then chequing i enter the amoint of 500 but i get a garbage value of total. but when i enter for saving it works. can someone help me
    Code:
    #include<stdio.h>
    #include<conio.h>
    #include <stdlib.h>
    
    
    //void saving();
    int chooseAccountType(void);
    //int checkingtotal(int a);
    main()
    {     int num;
          int a=0,b=0;
          char ct;
          int ta;
          int aaa,aa,bb;
          int total,total1;
          int to;
          do 
          {
                
                   char a;
                   printf("\n\n\n\t\tThe Main Menu\n");
                   printf(" a) Deposit\n");
                   printf(" b) Withdraw\n");
                   printf(" c) Add Interest\n");
                   printf(" d) Account Balance\n");
                   printf(" e) Exit\n");
                   printf("Please select one of the choices above (a -> e):");
                   scanf(" %c",&ct);  
            
           if(ct=='a'||ct=='A')
           {
                  aaa= chooseAccountType();
                  printf("the number is%i",aaa);
                  if(aaa==1)
                  {
                  printf("\nAmmount to be deposit in chequiking=>");
                  scanf(" %i",&aa);    
                  num=num+aa;
                  printf("total %i aa %i",num,aa);
                  }  
                  else if(aaa==2)
                 {       
                 printf("\nAmmount to be deposit in saving=>");
                 scanf(" %i",&bb);
                 total1=total1+bb;
                  printf("total1 %i bb %i",total1,bb);
                 }  
          }
          else if(ct=='b'||ct=='B')
          {
          
          }
          else if(ct=='c'||ct=='C')
          {
          }
          else if(ct=='d'||ct=='D')
          {
                 aaa= chooseAccountType();
                 printf("number two %i", aaa);
                 if(aaa==1)
                 {
                 printf("Account Balance for checking=>%i",total);    
                 }  
                 else if(aaa==2)
                 {
                 printf("Account Balance for saving=>%i",total1);
                 }
          }
          else
          {
          printf("invalid Selection");
          }
    }
    while(ct!='e');
       
       getch();
    }
    
    int chooseAccountType(void)
    {
         int aa,b;
         
         printf("\n1)Chequing");
         printf("\n2)Saving");
         printf("\nWhich Account would you like to use=>");
         scanf(" %i",&aa);
         if(aa==1)
         {       
         return(aa);
         }
         else if(aa==2)
         {      
         return(aa);
         }     
    }

  2. #2
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Code:
      if(aaa==1)
                  {
                  printf("\nAmmount to be deposit in chequiking=>");
                  scanf(" %i",&aa);    
                  num=num+aa;
                  printf("total %i aa %i",num,aa);
    You never put a value into total when you make you deposit into checking. You put the value into num. However when you print your checking balance you do this:
    Code:
    printf("Account Balance for checking=>%i",total);
    Which like all your other variables aren't initialized. You need to initialize all your variables prior to using them. Additionally, you should make your variable names descriptive, not this letter crap you are using.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by AndrewHunter View Post
    Code:
                   printf("\nAmmount to be deposit in chequiking=>");
    Which like all your other variables aren't initialized. You need to initialize all your variables prior to using them. Additionally, you should make your variable names descriptive, not this letter crap you are using.
    It might also help if he knew how to spell "chequing"

  4. #4
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by CommonTater View Post
    It might also help if he knew how to spell "chequing"
    LOL....that is what I call a bilingual fail.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed