Hey everyone, I have got this question in an assignment about a simplified SNAP card game. I have spent far too much time on this assignment and I still have not found a solution. Apparently the program should print SNAP and then finish if two identical values of two cards are put one after other.
The question is as follows:
Write a program to play a simplified form of the card game 'Snap'. The user inputs a card using a string of two characters e.g. 3D is the 3 of diamonds, JS is the jack of spades. (the suits are H C D and S, the values are 23456789TJQKA). Each card will be input on a line. When two cards of the same value are input one after the other, the program should respond with SNAP, and then finish.
e.g. Type in your cards:
3S
KH
AH
7C
7S
SNAP
This is what I have done so far, but I am still stuck and the program is not working as I want it to. I am not sure if I am taking the right steps or not. Please can any one help me, any help would be greatly appreciated.
Code:
#include <stdio.h>
#include <strng.h>
char card1[1], card2[1];
int main() {
printf("Type in card1: ");
strcpy(card1, "23456789TJQKA");
gets(card1);
printf("Type in card2: ");
strcpy(card2, "HCDS");
gets(card2);
while(card1!=card2) {
printf("Type in card1: ");
gets(card1);
printf("Type in card2: ");
gets(card2);
while(card1==card2) {
printf("SNAP\n");
}
}
}