Thread: Help (warning 'return' with a value in function returning void

  1. #1
    Registered User
    Join Date
    Dec 2017
    Posts
    7

    Post Help (warning 'return' with a value in function returning void

    Code:
    #include<stdio.h>
    #include<conio.h>
    void main()
    
    
    {
    	int a,b;
    	char op,ans;
    	
    	
    	printf("Select Operator ( + - * / )\n");
    	scanf("%c",& op);
    	printf("\n Enter 1st Digit:");
    	scanf("%d",& a);
    	printf("\n Enter 2nd Digit:");
    	scanf("%d",& b);
    	
    	switch (op)
    	{
    		case '+':
    			printf("\n %d+%d=%d",a,b, a+b);
    			break;
    			
    			
    		case '-':
    			printf("\n %d-%d=%d",a,b, a-b);
    			break;
    			
    		case '*':
    			printf("\n %d*%d=%d",a,b, a*b);
    			break;
    			
    		case '/':
    			printf("\n %d/%d=%d",a,b, a/b);
    			break;
            
    }
    	
    
    
    			
    	    printf("\n Are You Want to exit? [Y|N] ");
    		scanf("%d", & ans);
    	 
    	 if
    	 (ans == 'y' || ans == 'Y')  
    	 return 0;
    	 
    	 else
    	 (ans == 'n' || ans == 'N');
    	 return main();
    
    
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,076
    1. Main returns int, not void.
    2. Don't call main recursively. Use a loop inside main.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Banned
    Join Date
    Aug 2017
    Posts
    861
    I never tried that, calling main to loop. what a concept! Plus writing functions itself, having a return value at the end of a function and declaring it void as a return type?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Return 0 in a void function?
    By evilcubed in forum C Programming
    Replies: 17
    Last Post: 12-09-2012, 10:07 AM
  2. how to return in void function();
    By pczafer in forum C++ Programming
    Replies: 5
    Last Post: 05-03-2009, 03:06 PM
  3. warning: control reaches end of non-void function
    By franziss in forum C Programming
    Replies: 5
    Last Post: 01-29-2005, 11:46 PM
  4. function returning void
    By studentc in forum C Programming
    Replies: 14
    Last Post: 05-13-2004, 04:55 PM
  5. Replies: 4
    Last Post: 01-02-2002, 10:57 PM

Tags for this Thread