Thread: Writing a simplified cards game.

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    3

    Question Writing a simplified cards game.

    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]);
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You've got a thread on this already
    Help Needed please!!

    Read it, respond to it.
    We're not going to spoon-feed you the answer, no matter how many times you start a new thread.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I don't get how the following expression gets simplified
    By Overworked_PhD in forum C Programming
    Replies: 4
    Last Post: 06-05-2009, 05:15 PM
  2. headers simplified...please
    By jmartrican in forum C++ Programming
    Replies: 18
    Last Post: 02-11-2008, 01:52 AM
  3. How can this if else statement be simplified?
    By CookieMonster in forum C Programming
    Replies: 6
    Last Post: 04-06-2004, 04:12 PM
  4. Battle cards game
    By sagi4626 in forum C++ Programming
    Replies: 8
    Last Post: 05-04-2002, 03:04 AM
  5. Simplified code
    By soonerfan in forum C Programming
    Replies: 2
    Last Post: 12-05-2001, 03:50 PM