0

I have to write a program that reads in playing card values and translates them to the correct output. For example if a user enters:QS then the output would be a queen of spades. I am using a switch statement but how can I read the second character. Right now it just reads the first character and then prints out just that corresponding title.

2
Contributors
3
Replies
5
Views
11 Years
Discussion Span
Last Post by djbsabkcb
0

You should provide your existing code so that we can give specific recommendations. Basically, read both characters as a string. Then, send the first character via [0] to your switch, then send the second character via [1] to a different switch.

0

I have included my code below I have done so far for this program. But based on your suggestion it sounds like I need to come up with another way of doing it because of redundancy. Maybe I should use if/else statements.

Thanks,

// This program will determine the deck of cards you have
// For example, if you type AD then the output will be Ace of Diamonds.

#include <iostream>

using namespace std;


int main()
{


        cout << "               MENU            " << endl;
        cout << "------------------------------------" << endl;
        cout << " A=Ace, J=Jack, Q=Queen " << endl;
        cout << " K=King, D=Diamonds, H=Hearts"<< endl;
        cout << " S=Spades,C=Clubs,2-10=card values" << endl;
        cout << "------------------------------------" << endl;


        while ( true)
        {
        cout << " Enter the card notation: (ex. QS,AD,4C): ";


        char choice;
        cin >> choice;
        if ( cin.eof() )
                break;



                switch (choice)
                {

                        case 'q':
                        case 'Q':
                                cout << " Queen " << endl ;
                                break;
                        case 'a':
                        case 'A':

<< moderator edit: added code tags: [code][/code] >>

0

I have included my code below I have done so far for this program. But based on your suggestion it sounds like I need to come up with another way of doing it because of redundancy. Maybe I should use if/else statements.

// This program will determine the deck of cards you have
// For example, if you type AD then the output will be Ace of Diamonds.

#include <iostream>

using namespace std;


int main()
{


        cout << "               MENU            " << endl;
        cout << "------------------------------------" << endl;
        cout << " A=Ace, J=Jack, Q=Queen " << endl;
        cout << " K=King, D=Diamonds, H=Hearts"<< endl;
        cout << " S=Spades,C=Clubs,2-10=card values" << endl;
        cout << "------------------------------------" << endl;


        while ( true)
        {
        cout << " Enter the card notation: (ex. QS,AD,4C): ";


        char choice;
        cin >> choice;
        if ( cin.eof() )
                break;



                switch (choice)
                {

                        case 'q':
                        case 'Q':
                                cout << " Queen " << endl ;
                                break;
                        case 'a':
                        case 'A':

<< moderator edit: added [code][/code] tags >>

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.