Generates a random number

hello my friends
i have a problem with generating random number.
i wrote this program
#include "stdafx.h"
#include <iostream>
using namespace std;
int main ()
{
for(int c=1;c<=20;c++)
{
cout<<1+rand()%6;
if(c%5==0)
cout<<endl;
}
}

but its generated so many numbers,i want to write a program to generate one random number each time for me.
i want this program for <<DICE>>.
please help me.
Thank You.

in fact i want a program that recieve number from 1 to 100 from user,and give user a number between 1 to 6.
I don't understand what you want exactly. Anyway you miss the initialization of the rand function: use the srand at the beginning of your main.
look at the program i wrote
that program generated 6 or more random number.
i want a program that generate and make 1 number eachtime.
sorry for my english.
Then you should not put your cout << ...rand... inside the for loop. Otherwise it's obvious that the code will be executed more than once!
please re-write it for me.thanks
why should we do it? It's your code.
Topic archived. No new replies allowed.