Results 1 to 4 of 4

Thread: C++ slot machine

  1. #1
    Join Date
    Apr 2009
    Posts
    87

    C++ slot machine

    I am trying to write a simple C++ slot machine program to run three number A , B and C. The problem is no are not generating number randomly.
    Code:
    // slot machine
    #include<iostream>
    #include<cstdlib>
    #include<ctime>
     
    using namespace std;
     
    int main()
    {
    int number A = 0, number B = 0, number C = 0;
     
    srand (time(0));
    int Y; 
     
    for (Y = 0; Y < 3; Y++)
    {
    int random = rand(); 
    int number  = (random % 3) + 1;  
    cout << number  << " ";
    }
     
    return 0;
    }

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: C++ slot machine

    Code:
    bool number = true;
    for (Y = 0; Y < 3; Y++)
    {
         // create random number
         if (/* condition */)
             number = false;
    
         // code
    }
    
    if (number)
         cout << "You are winner.";
    else
         cout << "You are looser.";

  3. #3
    Join Date
    Jan 2009
    Posts
    199

    Re: C++ slot machine

    When you are calling a variable in function :
    Code:
    cout<<"You win\n"; 
    function name();
    If they win you need
    Code:
    cout<<"You lose\n"; 
    cin.get(); 
    function name();

    to execute if they lose

  4. #4
    Join Date
    Dec 2008
    Posts
    177

    Re: C++ slot machine

    You can define 3 variables (A,B and C) to hold the numbers c++ slot machine and then use if (Statement) to get a true or false.

Similar Threads

  1. Replies: 5
    Last Post: 11-06-2011, 10:26 PM
  2. Homefront: purchasing Slot 1 and Slot 2
    By Edgar Arular in forum Video Games
    Replies: 5
    Last Post: 13-03-2011, 06:00 PM
  3. Difference between Single slot and Dual slot graphic card
    By Valdis in forum Monitor & Video Cards
    Replies: 5
    Last Post: 15-12-2010, 10:14 AM
  4. C++ Slot machine program
    By DizyD07 in forum Software Development
    Replies: 2
    Last Post: 07-12-2009, 07:50 PM
  5. Replies: 3
    Last Post: 10-05-2007, 09:03 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,903,752.44291 seconds with 16 queries