Declaring a function (HELP)

I just created a random number generator within main. Following that I attempted too put it into is on function called "random". When attempting too call this function I received this error message... Can someone please help me out!

Error Message: 'random' undeclared (first use this function)




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main(){
  
random(); 
    
    
  system("PAUSE");   
  return 0;
}


int random(){
    srand(time(0));
  for(int x =1; x<25;x++){
          cout << 1+(rand()%6) << endl;  
          }

    
    
  
    }
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int Random();

int main(){
  
Random(); 
    
    
  system("PAUSE");   
  return 0;
}


int Random(){
    srand(time(0));
  for(int x =1; x<25;x++){
          cout << 1+(rand()%6) << endl;  
          }

    
    
  
    }
Last edited on
closed account (zb0S216C)
random must either have a prototype (recommended) or moved above main(). A prototype allows the compiler to perform type-checking against the parameters and arguments when the function is invoked (called).

Here's an example of a prototype:

1
2
3
4
5
6
7
8
9
int random(); // Prototype

int main()
{
}

int random() // Definition
{
}


Wazzak
Last edited on
Thanks for the help and explanation guys!

Topic archived. No new replies allowed.