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, JSis 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. I want to pick out the first value from card1 and compare it with second value of the card 2 and see if they match so the programm can print out SNAP at the End. any help would be greatly appreciated.
Code:
#include <stdio.h>
#include <string.h>
char card1[3],char card2[3];
int main() {
printf("Type in card1: ");
scanf("%s", card1);
printf("Type in card2: ");
scanf("%s", card2);
strcmp(card1[1],card2[1]);
}