Code help needed

This is a discussion on Code help needed within the C Programming forums, part of the General Programming Boards category; Hello, iam making a atm to calculate some items. in the program i ask for a deposit and it does ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    5

    Code help needed

    Hello, iam making a atm to calculate some items. in the program i ask for a deposit and it does show. Then i as for balance which does show but at2x the variable i put in. I really have no clue as to what is causing the variable to multiple by 2 when i as for it to be seen in the account balance option.

    Code:
    
    
    
    #include<stdio.h>
    #include<math.h>
    int chooseaccounttype(void);
    float Compound(float,int);
    main()
    
    {
    	char select;
    	float deposit=0,withdraw=0,sum1=0,sum2=0,interest=0;
    	int accountchoice,months;
    	do{
    	printf("\n\n\n\ta)  Deposit");
    	printf("\n\tb)  Withdraw");
    	printf("\n\tc)  Add Interest");
    	printf("\n\td)  Account Balance");
    	printf("\n\te)  Exit");
    	printf("\n\n\tPlease select one of the choices above (a -> e)");
    	fflush(stdin);
    	scanf("%c",&select);
    	getchar();
    	system("cls");
    	
    	
    	switch (select)
    		{
    			case 'A':
    			case 'a':
    				printf("\n\n\tenter amount to deposit-->");
    				fflush(stdin);
    				scanf("%f",&deposit);
    				fflush(stdin);
    				system("cls");
    				accountchoice=chooseaccounttype();
    				printf("You deposited $ %.2f",deposit);
    					getch();
    					system("cls");
    					break;
    			case 'B':
    			case 'b':
    				printf("enter amount to withdraw");
    				scanf("%f",&withdraw);
    				system("cls");
    				accountchoice=chooseaccounttype();
    			break;
    			case 'C':
    			case 'c':
    				printf("Enter the interest");
    				scanf("%f",&interest);
    				printf("\n Enter the amount of months");
    				scanf("%i",&months);
    				accountchoice=chooseaccounttype();
    				getch();
    			break;
    			case 'D':
    			case 'd':
    				accountchoice=chooseaccounttype();
    			break;
    			case 'E':
    			case 'e':
    				printf("last check");
    				getch();
    			break;
    		
    			default:
    				printf("\tinvalid Selection");
    				getch();
    				system("cls");
    			break;
    			}
    	switch(accountchoice)
    	{
    	case 1:
    		if(select=='a'||'A')
    		{
    			sum1= sum1+deposit;
    		printf("Your new balance is %.2f",sum1);
    		}
    		else 
    		if(select=='b'||'B')
    		
    			if(sum1<withdraw)
    			{
    				printf("Insuffient funds");
    			}
    			else if(sum1>=withdraw)
    			{
    		sum1=sum1-withdraw;
    		fflush(stdin);
    		printf("your new balance is %.2f",sum1);
    		fflush(stdin);
    		}
    
    		else if(select=='c'||'C')
    	{
    
    		}
    		else 
    		{
    			printf("u have %f",sum1);
    			getch();
    		}
    		break;
    	
    	
    	
    	
    	case 2: puts (" savings");
    		break;
    	}
    
    
    
    
    
    
    	}while(select!='e' && select!='E');
    }
    	int chooseaccounttype(void)
    	{
    		int account;
    			printf("\n\t\t1) Chequing"); 
    			printf("\n\t\t2) Savings");
    			printf("\n Please select the account type:");
    			fflush(stdin);
    			scanf("%i",&account);
    			switch(account)
    			{
    			case 1:	
    			return(1);
    			break;	
    			case 2: 
    			return(2);
    			break;
    			}
    			
    	}
    only account chequing is done for now so use that instead of savings. I cheacked my code long and i cant figure out what the problem is, any insight would be helpfull.

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649
    fflush(stdin) is failure #1: Cprogramming.com FAQ > Why fflush(stdin) is wrong

    Code:
    if(select=='a'||'A')
    is failure #2. You cannot do compound boolean statements like that, you must be explicit:
    Code:
    if (select == 'a' || select == 'A')

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Humorous Code
    By DavidP in forum General Discussions
    Replies: 16
    Last Post: 08-28-2010, 10:40 AM
  2. help needed with simple code
    By Branka in forum C++ Programming
    Replies: 1
    Last Post: 08-17-2005, 10:25 AM
  3. Help needed w/ line of code..Thanks!
    By aspand in forum C Programming
    Replies: 7
    Last Post: 05-30-2002, 04:12 PM
  4. Help Needed W/ Code..please!!
    By aspand in forum C Programming
    Replies: 3
    Last Post: 05-28-2002, 02:51 PM

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