Problem with rand()
From: RJB (robartleNOSPAM_at_hotmail.com)
Date: 02/10/04
- Next message: Richard Heathfield: "Re: Problem with rand()"
- Previous message: NONE: "Re: if problem"
- Next in thread: Richard Heathfield: "Re: Problem with rand()"
- Reply: Richard Heathfield: "Re: Problem with rand()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 9 Feb 2004 19:04:21 -0500
Hi all,
I'm doing some homework and am kind of stuck here. I'm doing a program that
needs two random numbers to be multiplied. Here is my code so far:
#include <iostream>
#include <cstdlib>
using namespace::std;
int main()
{
int x = ( 1 + rand() % 9 );
int y = ( 1 + rand() % 9 );
int ans = 0;
cout << "How much is " << x << " times " << y << "?" << endl;
return 0;
}
As I understand it the ( 1 + rand() % 9 ) should return a random number
between 1 and 9. Is this correct? I seem to be getting the same set of
numbers each time it is run. Can you tell I'm a newb? <g>
Thanks for any help.
- Next message: Richard Heathfield: "Re: Problem with rand()"
- Previous message: NONE: "Re: if problem"
- Next in thread: Richard Heathfield: "Re: Problem with rand()"
- Reply: Richard Heathfield: "Re: Problem with rand()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|