Solved
Program that return random number
Posted on 2004-04-13
Hi, there is an error in this program, and I can not see it. Please help me.
Program should set up an overloaded function set called GetRandomNum. This function return a random number that is generated with srand() and rand(). There should be three different prototypes for this function:
int GetRandomNum(int m);
int GetRandomNum(int i, int j);
double GetRandomNum();
Program should make three calles to GetRandomNum: once otaining a number between 0 and 27, once otaining a number between 3 and 73, and last obtaining a number between 0.000 and 1.000. All three numbers should be displayed to the screen.
#include <iostream.h>
#include <stdlib.h>
#include "GetRandomNum.h"
int GetRandomNum(int m);
int GetRandomNum(int i, int j);
double GetRandomNum();
int main(void)
{
int rnum;
double dnum;
srand(980);
cout << "\n Enter random number between 0 and 27 \n\n";
cout << "\n The random number is << rnum;
GetRandomNum(27);
cout << "\n Enter random number between 3 and 73 \n\n";
GetRandomNum(3,73);
cout << "\n Enter random number between 0.000 and 1.000 \n\n";
GetRandomNum(0.0,1.0);
return 0;
}
int GetRandomNum(int)
{
int rnum;
rnum=rand() % m;
return rnum;
}
int GetRandomNum(int, int)
{
int rnum;
rnum=rand() % (j-i-1);
rand=rand() % (i+1);
return rnum;
}
double GetRandomNum()
{
double dnum;
cout.precision(3);
cout.flags(ios::fixed | ios::showpoint);
dnum=rand() % 1000/1000;
return dnum;
}
Thanks,
mocca23