Thread: errors in multi-selection program

  1. #1
    Un Artiste Extraordinaire volk's Avatar
    Join Date
    Dec 2002
    Posts
    357

    Question errors in multi-selection program

    Code:
    #include <stdio.h>
    
    int getOption (void);
    
    float add2 (float num1, float num2);
    float sub2 (float num1, float num2);
    float mul2 (float num1, float num2);
    float div2 (float num1, float num2);
    
    void pirintResult (float num1, float num2, float result, int option);
    
    int main (void)
    {
    	int   done = 0;
    	int   option;
    	float num1;
    	float num2;
    	float result;
    
    	while (!done)
    	{
    		option = getOption();
    		if (option == 5)
    			done = 1;
    		else
    		{
    			do
    			{
    				printf("\n\nEnter two numbers: ");
    				scanf ("%f %f", &num1, &num2);
    				
    				if (option == 4 && num2 == 0)
    				{
    					printf("\n\n *** Error *** ");
    					printf("Second number cannot be 0\n");
    				} while (option == 4 && num2 == 0);
    
    			switch (option)
    				{
    				case 1: result = add2 (num1, num2);
    						break;
    				case 2: result = sub2 (num1, num2);
    						break;
    				case 3: result = mul2 (num1, num2);
    						break;
    				case 4: result = div2 (num1, num2);
    				}
    
    			printResult (num1, num2, result, option);
    			}
    		}
    	printf("\nThank you for using this Calculator.\n");
    
    	return 0;
    }
    
    int getOption (void)
    
    {
    	int option;
    
    	do
    	{
    		printf("\n***************");
    		printf("\n*     MENU    *");
    		printf("\n*             *");
    		printf("\n* 1. ADD      *");
    		printf("\n* 1. SUBTRACT *");
    		printf("\n* 1. MULTIPLY *");
    		printf("\n* 1. DIVIDE   *");
    		printf("\n* 1. QUIT     *");
    		printf("\n*             *");
    		printf("\n***************");
    
    		printf("\n\n\nPlease type your choice ");
    		printf("and press the return key : ");
    		scanf ("%d", &option);
    
    		if (option < 1 || option > 5)
    			printf("\nInvalid option.  Pleae re-enter.\n");
    
    	} while (option <1 || option > 5);
    
    	return option;
    }
    
    }
    Why do I keep getting errors with this program?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    That's a good question. How about you do us all a favour and post what errors you are getting?

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Un Artiste Extraordinaire volk's Avatar
    Join Date
    Dec 2002
    Posts
    357

    Talking

    Originally posted by quzah
    That's a good question. How about you do us all a favour and post what errors you are getting?

    Quzah.
    You're always mean to me, Quzah.

    Well, how about you copy the code into your compiler to see the errors for yourself?

    Copy and paste shouldn't be too much of hassle, no?

    Ok, ok, i'll post the errors:

    warning C4013: 'printResult' undefined; assuming extern returning int

    printResult (num1, num2, result, option);


    error C2059: syntax error : '}'

    printResult (num1, num2, result, option);
    }
    }


    error C2143: syntax error : missing ';' before 'type'

    int getOption (void)

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    76
    Your code has two errors:

    • pirintResult - I'm sure you mean printResult
    • An extra curly brace at the end of the file

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by volk
    You're always mean to me, Quzah.

    Well, how about you copy the code into your compiler to see the errors for yourself?
    No, I'm not mean. I'm to the point. When asking for help, it is your job to provide as much information as possible. You are actually asking people to take time out of their day to help you out. Don't you think it's fair to provide them with as much information as possible?

    Seriously, if you won't take the time to help me narrow down your problem, why should I take the time to help you find it?

    It's only common courtesy.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >> Well, how about you copy the code into your compiler to see the errors for yourself?
    A good coder can spot a vast number of problems by comparing the error messages with the source. Most of the time, proper debugging isn't required.

    >>Copy and paste shouldn't be too much of hassle, no?
    It might seem like a simple thing, but that doesn't always work. For example, on one of the PCs I use, if I cut/paste to my editor, all the code ends up on one line, and won't compile at all.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multi Thread Program Problem
    By ZNez in forum C Programming
    Replies: 1
    Last Post: 01-03-2009, 11:10 AM
  2. Replies: 6
    Last Post: 08-23-2008, 01:16 PM
  3. mega compile errors for small program
    By s_UNI_ in forum C++ Programming
    Replies: 4
    Last Post: 04-28-2005, 12:00 PM
  4. Multi file program?
    By zolo44 in forum C++ Programming
    Replies: 2
    Last Post: 07-01-2002, 04:29 PM
  5. I'm a newbie and I can't understand the errors in my program
    By iluvmyafboys in forum C++ Programming
    Replies: 19
    Last Post: 02-20-2002, 10:40 AM