| | |
memory game
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
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 |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






