CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: [RESOLVED] Virtual Slot Machine

  1. #1
    Join Date
    Apr 2009

    [RESOLVED] Virtual Slot Machine

    i want to write a virtual slot machine program, in the program i want to write a function which returns a random integer and i should call this function 3 times to get 3 different integers, what happens is that i get the same random integer 3 times, so please i want to know where is the problem in my code. If anyone read c++ for game developing module 1(game institute) he would be familiar with the program its in chapter 3 exercise 3.7.6:

    Here is my code:

    using namespace std;
    int random(int low,int high);
    int main(){
    int a[3];
    for(int i=0;i<3;i++){a[i]=random(2,7);}
    int random(int low,int high){
    int x=low+rand()%((high+1)-low);
    return x;}

  2. #2
    Join Date
    May 2002

    Re: Virtual Slot Machine

    srand() should be called only once - at the beginning of main() - not in the random() function().

  3. #3
    Join Date
    Apr 2009

    Re: Virtual Slot Machine

    thank u very much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)