| | |
memory game
![]() |
•
•
Join Date: Oct 2008
Posts: 11
Reputation:
Solved Threads:
0
Hi all i am working on a memory game and i am having problems inputing the data so it checks if a 3rd number is pulled up to ignore it
thanks in advance
thanks in advance
C++ Syntax (Toggle Plain Text)
int card[6][6],total=0,value,test; srand((unsigned)time(NULL));//randomize timer for (int i=0;i<6;i++) { for (int j=0;j<6;j++) { value=rand()%18;//random test=0; card[i][j]=value;//sets the value for (int x=0;x<6;x++) { for (int y=0;y<6;y++)//starts the check for doubles { if(value==card[x][y]) { test++; cout<<i<<endl; } if (test==3) { //need a code to stop for the 3rd one to be put in. } } } } }
So you want to populate the board with random numbers in the range of [0, 18) and disallow more than two of a kind? I'd say use a frequency table for the range since it's small, and repeat getting the random number until you find one that doesn't go beyond the limit:
The frequency table holds a count of all of the values in your range.
C++ Syntax (Toggle Plain Text)
#include <cstdlib> #include <iomanip> #include <iostream> int main() { using namespace std; int board[6][6]; int freq[18] = {0}; for ( int i = 0; i < 6; i++ ) { for ( int j = 0; j < 6; j++ ) { int r; do r = rand() % 18; while ( freq[r] >= 2 ); ++freq[r]; board[i][j] = r; } } for ( int i = 0; i < 6; i++ ) { for ( int j = 0; j < 6; j++ ) cout<< left << setw ( 3 ) << board[i][j]; cout<<'\n'; } }
I'm here to prove you wrong.
![]() |
Similar Threads
- Beautyfull Memory Game (Geeks' Lounge)
- Spark Game (Highly Addictive) (Geeks' Lounge)
- Memory game with c++ console applicaton (C++)
- why wont my flash game work? (Graphics and Multimedia)
- why i can not load game on one partition but can on aother (Troubleshooting Dead Machines)
- Freezes and Odd things after memory upgrade (Windows NT / 2000 / XP)
- Big Game need progrmmers (C++)
- SHUTDOWNS, new video card (Monitors, Displays and Video Cards)
Other Threads in the C++ Forum
- Previous Thread: Need homework help
- Next Thread: Free safe DLL to play with
| Thread Tools | Search this Thread |
ad api array based binary bitmap c++ c/c++ char class classes code coding compile console conversion count delete deploy desktop developer devlopment directshow dll download drawing duplication dynamic dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp homeworkhelper homeworksolution iamthwee ifstream input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node output pointer problem program programming project python random read recursion reference retarded-mentally rpg segmentationfault staticmembers string strings strtok temperature template test text text-file tree troubleshoot update upload url variable vector video win32 windows winsock wordfrequency wxwidgets






