help with my code easy

This is a discussion on help with my code easy within the C Programming forums, part of the General Programming Boards category; Sorry about another question. When choose option add interest i press 11 i get the right interest but when i ...

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

    help with my code easy

    Sorry about another question. When choose option add interest i press 11 i get the right interest but when i enter number of month 54 i get month 2. Or if i enter any other number i always get 2. why is that. Thank you for your help
    Code:
    #include<stdio.h>
    #include<conio.h>
    #include <stdlib.h>
    
    
    //void saving();
    int compound(float a, int b, int c);
    int chooseAccountType(void);
    //int checkingtotal(int a);
    main()
    {    
          char choice;
          int interest, month;
          int pick,cheq,sav;
          int total,total1,value;
          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",&choice);
            
           if(choice=='a'||choice=='A')
           {
                  pick= chooseAccountType();
                  printf("the number is %i",pick);
                  if(pick==1)
                  {
                  printf("\nAmmount to be deposit in chequiking=>");
                  scanf("%i",&cheq);    
                  total=total+cheq;
                  printf("total %i aa %i",total,cheq);
                  }  
                  else if(pick==2)
                 {       
                 printf("\nAmmount to be deposit in saving=>");
                 scanf(" %i",&sav);
                 total1=total1+sav;
                  printf("total1 %i bb %i",total1,sav);
                 }  
          }
          else if(choice=='b'||choice=='B')
          {
                  pick= chooseAccountType();
                  printf("the number is %i",pick);
                  if(pick==1)
                  {
                  printf("\nAmmount to be withdraw in chequiking=>");
                  scanf("%i",&cheq);    
                  total=total-cheq;
                  printf("total %i aa %i",total,cheq);
                  }  
                  else if(pick==2)
                 {       
                 printf("\nAmmount to be deposit in saving=>");
                 scanf(" %i",&sav);
                 total1=total1-sav;
                  printf("total1 %i bb %i",total1,sav);
                 } 
          }
          else if(choice=='c'||choice=='C')
          {
               
                printf("\nWhat is the interest rate to compound annually");
                scanf(" %i",&interest);
                printf("\ninterest%i",interest);
                
                printf("\nWhat is the number of month");
                scanf("% i",&month);                          // When i enter a value i get  an error always get 2
                printf("month%i",month);                    // error here
          
                pick= chooseAccountType();
                  printf("the number is %i",pick);
                  if(pick==1)
                  {
                            printf("heloo");
                   //value=compound(total,num,it);
                   
                  }  
                  else if(pick==2)
                 {   
                     printf("he");    
              // value=compound(total1,num,it);
                 } 
          }
          else if(choice=='d'||choice=='D')
          {
                 pick= chooseAccountType();
                 printf("number two %i", pick);
                 if(pick==1)
                 {
                 printf("Account Balance for chequing=>%i",total);    
                 }  
                 else if(pick==2)
                 {
                 printf("Account Balance for saving=>%i",total1);
                 }
          }
          else
          {
          printf("invalid Selection");
          }
    }
    while(choice!='e');
       
       getch();
    }
    
    int chooseAccountType(void)
    {
         int choice;
         
         printf("\n1)Chequing");
         printf("\n2)Saving");
         printf("\nWhich Account would you like to use=>");
         scanf(" %i",&choice);
         if(choice==1)
         {       
         return(choice);
         }
         else if(choice==2)
         {      
         return(choice);
         }     
    }
     
    int compound(float a, int b, int c)
    {
        
        
    };

  2. #2
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Please do not make a new post everytime you have a different question about the same program with the same code. This question should have been part of this thread you started less than an hour ago.

    That being said:
    Code:
    printf("\nWhat is the number of month");
    scanf("% i",&month);
    You have a spurious space in your scanf statement. it should be scanf(" %i", &month);
    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
    Registered User
    Join Date
    Feb 2010
    Posts
    96
    Thanks alot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with a easy C code problem
    By Mikethk in forum C Programming
    Replies: 4
    Last Post: 04-13-2011, 12:36 PM
  2. Very easy code I know...
    By UCFuser in forum C Programming
    Replies: 3
    Last Post: 01-20-2011, 06:56 PM
  3. Replies: 23
    Last Post: 04-20-2009, 08:35 AM
  4. Seg fault in easy, easy code
    By lisa1901 in forum C++ Programming
    Replies: 11
    Last Post: 12-10-2007, 05:28 AM
  5. i need help with a code (really easy)
    By yorge in forum C++ Programming
    Replies: 5
    Last Post: 04-21-2002, 02:55 PM

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