compiler errors

This is a discussion on compiler errors within the C++ Programming forums, part of the General Programming Boards category; I'm getting three compiler errors from VC++. It's saying that I have an undeclared identifier when I call the stuff ...

  1. #1
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463

    Question compiler errors

    I'm getting three compiler errors from VC++. It's saying that I have an undeclared identifier when I call the stuff function, and at my stuff function it says "redefinition; different type modifiers". I have no idea what's wrong with it, especially the first one. Someone please give me some light as to my problems.

    Code:
    #include <iostream>
    #include <stdio.h>
    
    using namespace std;
    
    int girls, boys;
    
    int main(void)
    {
    	int c1,input;
    	bool blah;
    
    	cout << "Number of iterations?" << endl;
    	cin>>input;
    
    	for(c1=0;c1<input;c1++)
    	{
    		blah=stuff();
    	}
    
    	cout<<endl<<endl<<"Number of Girls are: "<<girls<<endl<<"Number of Boys are: ";
    	cout<<boys<<endl<<endl<<"Probability of girls is: "<<(girls/(girls+boys));
    	return 0;
    }
    
    bool stuff(void)
    {
    	int c2,num1;
    
    	for(c2=0;c2<4;c2++)
    	{
    		num1=rand()%2;
    		if(num1==0)
    		{ girls++; return true; }
    		else
    		{ boys++; }
    	}
    	return false;
    }

  2. #2
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    The compiler is saying that because you didn't declare the stuff() function before main(). You need to declare a function by including its prototype before main().
    Code:
    using namespace std;
    
    bool stuff(void);
    
    int main()
    {//etc.
    That ought to do it.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  3. #3
    NIM
    NIM is offline
    Registered User
    Join Date
    Oct 2003
    Posts
    24
    It would also be wise to use the updated C++ standard library header files.

    change

    Code:
    #include <stdio.h>
    to

    Code:
    #include <cstdio>
    You might be able to use the stdio.h and not run into any problems, but it is generally good programming practice to update your header files.

  4. #4
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    thanks! It's always the little, basic things that I forget first

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 10:13 AM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 11:50 AM
  3. bloodshed compiler errors
    By nerore in forum C++ Programming
    Replies: 5
    Last Post: 04-17-2004, 03:37 PM
  4. How to resolve linking errors?
    By m712 in forum C++ Programming
    Replies: 3
    Last Post: 11-03-2002, 10:17 PM
  5. Compiler errors
    By BellosX in forum C Programming
    Replies: 2
    Last Post: 09-21-2001, 04:24 AM

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