Thread: Yahtzee C++ programme help

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    21
    ive done this so far,
    but how do u keep the dice that i want and re roll the one i didnt keep?
    Code:
    #include <iostream>
    #include <cstdlib>
    #include <ctime>
    using namespace std;
    
    
    int main()
    {
     	int nums[5];
    	int i, j, input;
     
    	time_t t;
    	int count[6];
    
    	srand(time(&t)); /* seed the random number generator */
    	
    	for(j= 0; j < 14; j++)
    	{
    	for(i = 0; i < 5; i++)
      	{
        	nums[i] = rand()&#37;6 + 1;
        	cout << nums[i] << endl;
    		switch(nums[i])
    		{
    			case 1: ++count[0]; break;
    			case 2: ++count[1]; break;
    			case 3: ++count[2]; break;
    			case 4: ++count[3]; break;
    			case 5: ++count[4]; break;
    			case 6: ++count[5]; break;
    			default: cout << "An error has occured!"; break;
    		}
    	}
    	cout << "Choose which numbers you want to keep?( -1 to keep all numbers ) \n";
    	
    	
    	"\n";
    	cin >> input;
    	
        if(input == -1)
             break;
    	if (input > 6) cout << "Please select number from 1 to 6 only \n";
    	
    	'\n';
    	}
    	
    	if ( 
    	
    
      return 0; 
    }

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, the array nums hold your current dice, right? Then you select one or more to roll again?

    In this case, you'll have to have an array of which dice to keep and which to roll again - and obviously just roll the ones that are listed as "roll again".

    I would also suggest that your move the counting of each digit to after you've rolled again.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Closing a programme with cin.get
    By Dontgiveup in forum C++ Programming
    Replies: 2
    Last Post: 03-14-2009, 02:35 PM
  2. How to view the programme before it disappears
    By yousuf in forum C Programming
    Replies: 2
    Last Post: 03-22-2008, 08:12 AM
  3. Replies: 3
    Last Post: 05-13-2007, 08:55 AM
  4. Gui Programme does'nt Compiles from DOS
    By Shadowhunt in forum C++ Programming
    Replies: 1
    Last Post: 06-06-2003, 08:05 AM
  5. Simple C++ GUI programme does'nt run from dos
    By Shadowhunt in forum C++ Programming
    Replies: 4
    Last Post: 05-31-2003, 05:30 AM