Can u please tell what is the error in the program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DevR93
    New Member
    • Dec 2013
    • 1

    Can u please tell what is the error in the program

    Can anyone please tell me what is the error and how should i correct it. Its showing the following error in line 10-
    "[Error] expected expression before ',' token"
    this is my program-
    Code:
    #include<stdio.h>
    #include<conio.h>
    main()
    {
    	int a, b, sum, sub, mul, div;
    	printf("Enter the two numbers",a,b);
    	scanf("%d%d", &a, &b);
    	printf("Enter the choice of operation");
    	scanf("%d",&sum,&sub,&mul,&div);
    	switch(+,-,*,/)
        {
        	case "+": sum=a+b;
        	        printf("The sum of %d and %d is %d", a, b, sum);
        	        break;
        	case "-": sub=a-b; 
    		        printf("The difference of %d and %d is %d", a, b, sub);
    				break;
    		case "*": mul=a*b;
    		        printf("The product of %d and %d is %d", a, b, mul);
    		        break;
    		case "/": div=a/b;
    		        printf("The division of %d and %d is %d", a, b, div);
    				break;
    	    default :print("Enter the correct value");   
    		 		break;			     
        }
        return(0);
    	getch();
    }
    Last edited by zmbd; Dec 13 '13, 06:00 PM. Reason: [Z{Please use the [CODE/] button to format posted code/html/sql/formated text - Please read the FAQ}]
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    It means that you have a syntax error and that it happens prior to a comma in your code. Thus, you need to look at the function you are trying to use at that point, and the documentation and see wherein the error lies.

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      One error is here:

      Code:
       printf("Enter the two numbers",a,b);
      You need to tell printf how to display the variables. Besides that, it is odd you want to display the variables before they are entered.

      I suspect you added this printf by doing a copy/paste from another printf and forgot to remove the variable names.

      Comment

      • Mariostg
        Contributor
        • Sep 2010
        • 332

        #4
        Code:
        switch(+,-,*,/)
        Your switch statement must contain the name of the variable against which you want to execute the case statements, not the options you are looking after.

        Comment

        • zmbd
          Recognized Expert Moderator Expert
          • Mar 2012
          • 5501

          #5
          @Mariostg : which is why I asked OP to look-up the syntax...

          Comment

          • aselvan07
            New Member
            • Dec 2013
            • 4

            #6
            The error itself says that you are using arithmetic operators without an expression. If you were intention was to select a case based on the type of the operator, try putting them inside single quotes (treats it as a character). Although, I don't know what good that would do, since the last character in your list will win.

            Comment

            Working...