Thread: Can't run, dunno what is the problem

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    16

    Can't run, dunno what is the problem

    Hi I am just a beginner in programming. Please help as I can't run the program.

    Code:
    #include<stdio.h>
    
    void displayMenu();
    void addition();
    void looping();
    
    void main()
    
    {
    
    	displayMenu();
    	looping();
    }
    
    void displayMenu()
    
    {
    	int choice;
    
    	printf("(1)Addition problem\n");
    	printf("(2)Subtraction problem\n");
    	printf("(3)Quit the Program\n");
    	printf("Plese press a number to make your selection: ");
    	scanf("%d",&choice);
    }
    
    void addition()
    {
    	int a,b,c,d;
    
    	printf("2+3= \n");
    	scanf("%d",&a);
    
    	if(a==5)
    
    		printf("Right\n");
    
    	else
    
    		printf("Wrong\n");
    
    	printf("3+4= \n");
    	scanf("%d",&b);
    
    	if(b==7)
    
    		printf("Right\n");
    
    	else
    
    		printf("Wrong\n");
    
    	printf("6+2= \n");
    	scanf("%d",&c);
    
    	if(c==8)
    
    		printf("Right\n");
    
    	else
    
    		printf("Wrong\n");
    
    	printf("3+1= \n");
    	scanf("%d",&d);
    
    	if(d==4)
    
    		printf("Right\n");
    
    	else
    
    		printf("Wrong\n");
    }
    
    void subtraction()
    {
    	int a,b,c,d;
    
    	printf("3-3= \n");
    	scanf("%d",&a);
    
    	if(a==0)
    
    		printf("Right\n");
    
    	else
    
    		printf("Wrong\n");
    
    	printf("4-3= \n");
    	scanf("%d",&b);
    
    	if(b==1)
    
    		printf("Right\n");
    
    	else
    
    		printf("Wrong\n");
    
    	printf("6-2= \n");
    	scanf("%d",&c);
    
    	if(c==4)
    
    		printf("Right\n");
    
    	else
    
    		printf("Wrong\n");
    
    	printf("3-1= \n");
    	scanf("%d",&d);
    
    	if(d==2)
    
    		printf("Right\n");
    
    	else
    
    		printf("Wrong\n");
    }
    
    void looping(int choice)
    
    {
    	if(choice==1)
    	{
    		addition();
    	}
    
    	else if(choice==2)
    	{
    		subtraction();
    	}
    
    	else
    	{
    		printf("You must select 1 or 2\n");
    	}
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    displayMenu() does not return a value (your choice)

    looping() is declared and called with zero parameters, yet the definition expects a parameter.
    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
    Registered User
    Join Date
    Oct 2010
    Posts
    16
    Thank you, I have just change my codes to:

    Code:
    #include<stdio.h>
    
    int displayMenu();
    void addition();
    void subtraction();
    void looping(int);
    
    void main()
    
    {
    	int c;
    	c=displayMenu();
    	looping(c);
    }
    
    int displayMenu()
    
    {
    	int choice;
    
    	printf("(1)Addition problem\n");
    	printf("(2)Subtraction problem\n");
    	printf("(3)Quit the Program\n");
    	printf("Plese press a number to make your selection: ");
    	scanf("%d",&choice);
    	return choice;
    }
    
    void looping(int c)
    
    {
    	if(c==1)
    	{
    		addition();
    	}
    
    	else if(c==2)
    	{
    		subtraction();
    	}
    
    	else
    	{
    		printf("You must select 1 or 2\n");
    	}
    }
    I always have a hard time remembering the formats/syntax.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. triggering another program to run using serial port
    By infineonintern in forum C++ Programming
    Replies: 3
    Last Post: 07-22-2009, 05:16 AM
  2. problem: online on winxp and linux red hat
    By gemini_shooter in forum Linux Programming
    Replies: 5
    Last Post: 05-29-2005, 02:14 PM
  3. Input File HELP, weird problem
    By gravity-1 in forum C++ Programming
    Replies: 5
    Last Post: 03-29-2005, 08:43 PM
  4. linked list problem
    By kzar in forum C Programming
    Replies: 8
    Last Post: 02-05-2005, 04:16 PM
  5. Edit Control problem
    By Malek in forum Windows Programming
    Replies: 3
    Last Post: 06-16-2002, 01:12 AM