Hi, I need help with my assignment. •Create a memory game in C •Function oriente
ID: 3836997 • Letter: H
Question
Hi, I need help with my assignment.
•Create a memory game in C
•Function oriented with several functions
•Structured programming
•All cards are randomly placed on the board with face down •The player pick one card from the board and the symbol is shown •The player picks another card, with the aim to get pair (same symbol twice), and the symbol is shown
•If two equal card is found (pair) the player gets one point and the pair is removed from the board •The game continues until the board is empty
•NxM board size •Random board
my code not working becaus I cant get the random board to work.
Thanks
Explanation / Answer
#include "stdafx.h"
#include "stdlib.h"
#include <stdio.h>
#include <cstdlib>
#include <ctime>
int _tmain(int argc, _TCHAR* argv[])
{
char comma;
int r1, c1, r2, c2, cards[4][4];
srand((unsigned)time(NULL));
//fill board
for (int r=0; r<4; r++)
{
for (int c=0; c<4; c++)
{
cards[r][c]=rand()%8+1;
//display board
printf(" 1 2 3 4 ");
printf("");
for (int i=0; i<=8; i++)
{
printf("-");
}
printf("");
for (int r=0; r<4; r++)
{
printf("%d",r+1);
for (int c=0; c<4; c++)
{
printf("*");
}
printf("");
}
printf("");
//selection
printf(" enter first card row and column:. ");
scanf("%d,%d",&r1,&c1);
printf("enter second card row and column:. ");
scanf("%d,%d",&r2,&c2);
//fix
r1--;
c1--;
r2--;
c2--;
//reveal
printf(" 1 2 3 4 ");
printf("");
for (int i=0; i<=8; i++)
{
printf("-");
}
printf("");
for (int r=0; r<4; r++)
{
printf("%d",r+1);
for (int c=0; c<4; c++)
{
if ((r==r1)&&(c==c1))
{
printf("%d",cards[r][c]);
}
else if((r==r2)&&(c==c2))
{
printf("%d",cards[r][c]);
}
else
{
printf("*");
}
}
printf("");
}
//match?
if (cards[r1][c1]==cards[r2][c2])
{
}
else
{
}
printf("Enter 1 to play again. Enter 0 to quit: ");
scanf("%d",&r1);
if (r1 == 1)
{
system("CLS");
goto loop;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.