C funations Help

This is a discussion on C funations Help within the C Programming forums, part of the General Programming Boards category; Hell ive been working on a project given to me. I have done functions in prior assignments and now i ...

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

    C funations Help

    Hell ive been working on a project given to me. I have done functions in prior assignments and now i cant solve a problem. I recieve an error saying error C2143: syntax error : missing ';' before 'type' my code is
    Code:
    #include<stdio.h>
    #include<math.h>
    int chooseaccounttype();
    
    switch (select)
    		{
    			case 'A':
    			case 'a':
    				printf("enter amount to deposit");
    				scanf("%f",&x);
    				sum=y+x;
    				z=chooseaccounttype();
    				getch();
    				break;
    int chooseaccounttype(void)
    				{
    					int c;
    					printf("choose");
    					getch();
    					return 0;
    				}
    cant figure out what the problem is. suggestions would be help full

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,164
    Code:
    switch (select)
    		{
    			case 'A':
    			case 'a':
    				printf("enter amount to deposit");
    				scanf("%f",&x);
    				sum=y+x;
    				z=chooseaccounttype();
    				getch();
    				break;
    That whole chunk of code needs to be put into some function. Right now it's in limbo land. Where's your main() function?
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    5
    i have main and all i am just trying to now call a function from the case A-a how ever it gives of an error i can post my whole code if you would like.

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,164
    Quote Originally Posted by balhazar View Post
    i can post my whole code if you would like.
    I think that would probably be best.
    If you understand what you're doing, you're not learning anything.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Posts
    5
    this is the code
    Code:
    #include<stdio.h>
    #include<math.h>
    int chooseaccounttype(void);
    main()
    
    {
    	char select;
    	float y=0,x,z,sum;
    	int c;
    	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)");
    	scanf("%c",&select);
    	getchar();
    	system("cls");
    	}
    	int chooseaccounttype(void)
    	int c;
    	printf("choose");
    	getch();
    	return 0;
    				
    	
    		switch (select)
    		{
    			case 'A':
    			case 'a':
    				printf("enter amount to deposit");
    				scanf("%f",&x);
    				sum=y+x;
    				z=chooseaccounttype();
    				getch();
    				break;
    		
    			case 'B':
    			case 'b':
    				printf("check");
    				getch();
    			break;
    			case 'C':
    			case 'c':
    				printf("cheack");
    				getch();
    			break;
    			case 'D':
    			case 'd':
    				printf("total",sum);
    				getch();
    			break;
    			case 'E':
    			case 'e':
    				printf("last check");
    				getch();
    			break;
    		
    			default:
    				printf("\tinvalid Selection");
    				getch();
    				system("cls");
    			break;
    		
    			}while(select!='e' && select!='E');
    	}

  6. #6
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,164
    1) Check your braces.
    2) Your do-while loop seemingly ends before your switch statement.
    3) The chooseaccounttype() function should be defined outside of your main() function.

    It should be something like:
    Code:
    int chooseaccounttype(void);  // Function prototype
    
    int main(void)
    {
      // Code goes here
    }
    
    int chooseaccounttype(void)
    {
      // Code goes here
    }
    If you understand what you're doing, you're not learning anything.

  7. #7
    Registered User
    Join Date
    Nov 2010
    Posts
    5
    Quote Originally Posted by itsme86 View Post
    1) Check your braces.
    2) Your do-while loop seemingly ends before your switch statement.
    3) The chooseaccounttype() function should be defined outside of your main() function.

    It should be something like:
    Code:
    int chooseaccounttype(void);  // Function prototype
    
    int main(void)
    {
      // Code goes here
    }
    
    int chooseaccounttype(void)
    {
      // Code goes here
    }
    I have seen that type of code before on then net, however my prof never taught us how to do it the way you should with the intmain(void) then code. We usually put everything into one block of code instead of seperating it. I will try the way you have suggested,he told us to put everything inside the do while loop. Thank you!
    Last edited by balhazar; 11-29-2010 at 05:07 PM. Reason: forgot to add additional information

  8. #8
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by balhazar View Post
    I have seen that type of code before on then net, however my prof never taught us how to do it the way you should with the intmain(void) then code. We usually put everything into one block of code instead of seperating it. I will try the way you have suggested,he told us to put everything inside the do while loop. Thank you!
    Ok... to heck with your instructor. You need to learn C if you're going to pass the course and especially if you intend to write actual programs.

    Cprogramming.com Tutorial: Introduction to C

    Teach Yourself C in 21 Days -- Table of Contents

    C Programming

    C Tutorial

Popular pages Recent additions subscribe to a feed

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