-
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;
}
-
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.
-
It would also be wise to use the updated C++ standard library header files.
change
to
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.
-
thanks! It's always the little, basic things that I forget first:o