Problem with rand()

From: RJB (robartleNOSPAM_at_hotmail.com)
Date: 02/10/04


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.



Relevant Pages

  • Re: long integer multiplication
    ... integer multiplication.It's urgent. ... Please do your own homework or at least attempt to do your own homework ... and if you get stuck then post your code. ... int y = 0; ...
    (comp.lang.c)
  • Re: newb question: need help with homework assignment
    ... > int totalMinutes; ... Homework operator+const; ... I don't like more than one declaration per line ... Again you should learn about constructors. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Integer and character manipulation
    ... As for the second part, sorry, of course 3.142 isn't an int, just quick ... Posting the whole code wont probably help, as these are just two little ... It is not actually homework, ... Ian wrote: ...
    (comp.lang.c)
  • Re: String compare
    ... data in the form of 1's and 0's(data= 101010000011000001, could be int ... link and there was this algo of hamming distance... ... so I suspect it is homework. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: String compare
    ... i know what u mean by being it a homework... ... could be int or string). ... I was just thinking of ways to compare and cluster the data... ... or i can XOR each int and find the distance... ...
    (microsoft.public.dotnet.languages.csharp)