rand num generator help

So im trying to make a random number generator which i did but i have one problem, here is my code before i explain the rest:

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
28
29
30
31
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>

using namespace std;

void randnum();

//Main Program
int main()
{

    string type;

    randnum();

    if(type == rand()){
    cout "test";
    }

    return 0;
}

void randnum()
{
    int randnumber = rand(1);

    cout << rand();

}


what i want to do is show the user the random number that is generated and then i want them to have to type exactly what random number was generated but thats the problem i dont know how to do that,i tried here: if(type == rand()){ so basically i want them to type in the outputted number.
at first include
1
2
#include<time.h>
#include<stdlib.h> 

and write randum furnction like this
1
2
3
4
5
6
7
8
9
10
void randnum()
{
    int random;
    srand(time(NULL));
    for(int i=0;i<10;i++)
    {
    random=rand()%10;
    cout<<random<<endl;
    }
}

This function generate 10 random number for complete program and description visit this link http://codeincodeblock.blogspot.com/2011/10/generate-random-number-in-c.html
Ok but i need to use it in an if statement and thats the only part where im confused because the program needs to know what numbers were generated by the random number generator and when the user types them in it recognizes them
make the randnum() return type and check the return value
1
2
3
4
5
6
7
int randnum()
{
    int random;
    srand(time(NULL));
    random=rand()%10;
    return random;    
}
what would that look like?
Topic archived. No new replies allowed.