|
From: MD T <md...@re...> - 2004-11-11 03:08:14
|
=A0=0AHi All,=0A Good day,=0A I tried to develop progra=
ms in newly downloaded and installed dev c++ in my computer with windows Xp=
o/s.=0AAfter typing the program and pressing F9 i don't see the screen whi=
ch should show mw the result of the program. The log says g++ exe.and then =
some file names, execution terminated and compiled successfully. Can someon=
e tell me what is the mistake here? Or if there is a DEV C++ tutorial avail=
able?=0AI tried the following:=0A=0AGenerating a number in a specific range=
=0A=0AIf we want to produce numbers in a specific range, rather than betwe=
en 0 and RAND_MAX, we can use the modulo operator. It's not the best way to=
generate a range but it's the simplest. If we use rand()%n we generate a n=
umber from 0 to n-1. By adding an offset to the result we can produce a ran=
ge that is not zero based. The following code will produce 20 random number=
s from 1 to 10: =0A=0A=0A#include <cstdlib> =0A=0A#include <ctime> =0A#incl=
ude <iostream> =0A=0Ausing namespace std; =0A=0Aint main() =0A{ =0Asrand((u=
nsigned)time(0)); =0Aint random_integer; =0Afor(int index=3D0; index<20; in=
dex++){ =0Arandom_integer =3D (rand()%10)+1; =0Acout << random_integer << e=
ndl; =0A} =0A} =0A=0A=0A=0AA better method, though slightly more complicate=
d, is given below. This overcomes problems that are sometimes experienced w=
ith some types of pseudo random number generator that might be supplied wit=
h your compiler. As before, this will output 20 random numbers from 1 to 10=
. =0A=0A=0A=0A#include <iostream> =0A=0A#include <ctime> =0A#include <cstdl=
ib> =0A=0Ausing namespace std; =0A=0Aint main() =0A{ =0Asrand((unsigned)tim=
e(0)); =0Aint random_integer; =0Aint lowest=3D1, highest=3D10; =0Aint range=
=3D(highest-lowest)+1; =0Afor(int index=3D0; index<20; index++){ =0Arandom_=
integer =3D lowest+int(range*rand()/(RAND_MAX + 1.0)); =0Acout << random_in=
teger << endl; =0A} =0A}=0A=0AThe problem persists, Please look into this,=
=0AThanks and best regards,=0AMD T=0A |