Syntax Error- Please help

This is a discussion on Syntax Error- Please help within the C Programming forums, part of the General Programming Boards category; Hey guys, i'm getting an error that says "Undefined Reference to Gen2Rand" and i don't know how to fix that, ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    18

    Syntax Error- Please help

    Hey guys, i'm getting an error that says "Undefined Reference to Gen2Rand" and i don't know how to fix that, also is there a way to declare my variables inside of my main rather than globally? thanks for helping

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    #define SENT 4
    
    int r1;
    int r2;
    int *r1p;
    int *r2p;
    int c;
    
    void DisplayMenu (void);
    int GetMenuChoice (void);
    void Gen2Rand (int *r1p, int *r2p);
    void DrillOneProb (int c, int r1, int r2);
    /*==========>Main<==========*/
    
    void main (void)
    
    {
    
    	DisplayMenu();
    	GetMenuChoice();
    
    	while (c>=1 && c<SENT)
    		{
    			Gen2Rand(&r1, &r2);
    			DrillOneProb(c, r1, r2);
    			DisplayMenu();
    			GetMenuChoice();
    
    		}
    
    	printf("Program Complete.\n");
    }
    
    /*=====>DisplayMenu<=====*/
    
    void DisplayMenu (void)
    
    {
    
    	printf("MENU OF OPERATIONS\n\n");
    	printf("1. Addition.\n");
    	printf("2. Subtraction.\n");
    	printf("3. Multiplication.\n");
    	printf("4. Quit.\n\n");
    }
    
    /*====>GetMenuChoice<====*/
    
    int GetMenuChoice (void)
    
    {
    	int c;
    	do
    	{
    
    		printf("Enter the number of the operation to try (1-4): ");
    		scanf("%d", &c);
    		if(c<1 || c>SENT)
    			printf("\aInput value is out of range.\n");
    	}
    
    	while (c<1 || c>SENT);
    	return (c);
    }
    
    /*======>Get2Rand<=== ====*/
    
    void Get2Rand (int *r1p, int *r2p)
    
    {
    	int r1;
    	int r2;
    	r1= rand()%11 + 2;
    	r2= rand ()%11 + 2;
    	*r1p=r1;
    	*r2p=r2;
    
    }
    
    /*=====>DrillOneProb<=====*/
    
    void DrillOneProb (c, r1, r2)
    
    {
    	int CorAns;
    	int Reply;
    
    	printf("\nWhat is %d ", r1);
    
    	switch (c)
    	{
    	case 1: printf("+"); CorAns= r1+r2; break;
       	case 2: printf("-"); CorAns= r1-r2; break;
        default: printf("x"); CorAns=r1*r2; break;
        }
    	printf(" %d? ", r2);
    	scanf("%d", &Reply);
    		if (Reply=CorAns)
    			printf("Yes, that is correct. Good Job!");
    		else printf("No, the correct answer is: %d", CorAns);
    
    	printf("\n\n");
    
    }

  2. #2
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638

    Smile try

    void Gen2Rand (int (*r1p), int( *r2p));


    void Get2Rand (int (*r1p), int (*r2p) )

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    18
    where am i supposed to put those in? becuase i tried them in a couple different spots and no better results came out

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    It means check your spelling!!!

    Get != Gen

    Pick one and be consistent about it
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Sep 2003
    Posts
    18
    thanks soo much, but now i have run into a problem with the softcopy, after i enter in my number, no matter which i enter the program just completes. how do i fix that?

  6. #6
    Registered User
    Join Date
    Sep 2003
    Posts
    18
    ahhh now more problems lol

    Code:
    /*======>Get2Rand<=== ====*/
    
    int Gen 2Rand (int *r1p, int *r2p)
    
    {
    	int r1;
    	int r2;
    	r1= rand() % 11 + 2;
    	r2= rand() % 11 + 2;
    	*r1p=r1;
    	*r2p=r2;
    	return (r1, r2);
    }
    and there is something the matter where it doesn't recognize the return code or something, it says unrecognized declaration.

  7. #7
    Registered User
    Join Date
    Sep 2003
    Posts
    18
    ahhh this is horrible, okay i fixed that problem by deleting the return code and changine it to void instead of int but now the program still doesn't run right please help

  8. #8
    Registered User
    Join Date
    Sep 2003
    Posts
    18
    it might be a problem in my switch statement

  9. #9
    Registered User BillBoeBaggins's Avatar
    Join Date
    Oct 2003
    Posts
    107
    Problem 1:
    Get2Rand needed to be Gen2Rand.
    Problem 2:
    if you want r1p and r2p to act as pointers you need to reference them to the original variable. int *r1p=&r1;
    Problem 3:
    Your declared variable 'c' in your GetMenuChoice happens to be the same as your global variable, so... you need to rename the variable or come up with a work around... I would say Smart Pointers but that has to do with Classes and structures...
    Problem 4:
    This is an assignment if (Reply=CorAns) and this is a test if (Reply==CorAns).
    Problem 5:
    You never grabbed the results from the choices, c=GetMenuChoice();
    Problem 6:
    When displaying a value from a pointer, and the paramater is expecting a number.... you have to reference it... case 1: printf("+"); CorAns= *r1+*r2; break;



    Code:
    //--------------------------------------------------------
    //  Includes
    //--------------------------------------------------------
    #include <stdlib.h>
    #include <stdio.h>
    //---------------------------------------------------------
    // Proto Types
    //---------------------------------------------------------
    void DisplayMenu (void);
    int GetMenuChoice (void);
    void Gen2Rand (int *r1p, int *r2p);
    void DrillOneProb (int c, int *r1, int *r2);
    //---------------------------------------------------------
    //  Constants
    //---------------------------------------------------------
    #define SENT 4
    //---------------------------------------------------------
    //  Local Variables
    //---------------------------------------------------------
    int r1;
    int r2;
    int *r1p=&r1;
    int *r2p=&r2;
    int c;
    //---------------------------------------------------------
    //  Main Function
    //---------------------------------------------------------
    void main (void)
    {
    	DisplayMenu();
    	c=GetMenuChoice();	
    	while (c>=1 && c<SENT)
    		{
    			Gen2Rand(&r1, &r2);
    			DrillOneProb(c, &r1, &r2);
    			DisplayMenu();
    			c=GetMenuChoice();
    		}
    	printf("Program Complete.\n");
        system("PAUSE");	
    }
    //--------------------------------------------------------
    //  Support Functions
    //--------------------------------------------------------
    void DisplayMenu (void)
    {
    	printf("MENU OF OPERATIONS\n\n");
    	printf("1. Addition.\n");
    	printf("2. Subtraction.\n");
    	printf("3. Multiplication.\n");
    	printf("4. Quit.\n\n");
    }
    int GetMenuChoice (void)
    {
    	int ch;
    	do
    	{
    
    		printf("Enter the number of the operation to try (1-4): ");
    		scanf("%d", &ch);
    		if(ch<1 || ch>SENT)
    			printf("\aInput value is out of range.\n");
    	}
    	while (ch<1 || ch>SENT);
    	return (ch);
    }
    void Gen2Rand (int *r1p, int *r2p)
    {
        int r1;
    	int r2;
    	r1= rand()%11 + 2;
    	r2= rand ()%11 + 2;
    	*r1p=r1;
    	*r2p=r2;
    }
    void DrillOneProb (int c, int* r1,int* r2)
    {
    	int CorAns;
    	int Reply;
    	printf("\nWhat is %d ", *r1);
    	switch (c)
    	{
    	case 1: printf("+"); CorAns= *r1+*r2; break;
       	case 2: printf("-"); CorAns= *r1-*r2; break;
        default: printf("x"); CorAns=*r1**r2; break;
        }
    	printf(" %d? ", *r2);
    	scanf("%d", &Reply);
    		if (Reply==CorAns)
    			printf("Yes, that is correct. Good Job!");
    		else printf("No, the correct answer is: %d", CorAns);
    
    	printf("\n\n");
    }
    Attached Files Attached Files

  10. #10
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638

    Smile return

    also return can only return 1 variable. not 2 ie return(r1,r2)

  11. #11
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826

    Re: return

    Originally posted by kryptkat
    also return can only return 1 variable. not 2 ie return(r1,r2)
    Two items here:
    1) This is valid code, but no, it doesn't have the intended effect.
    2) Why are you returning anything, since both are pointers, which means you're modifying the original variable anyway?

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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 06:33 AM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM

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