Question: I'm working on a problem from a C++ textbook, and I'm not sure why my program isn't working correctly. I've attached the question and my

I'm working on a problem from a C++ textbook, and I'm not sure why my program isn't working correctly. I've attached the question and my code below:

P3.3 Write a program that takes user input describing a playing card with the following shorthand:

A = Ace

2...10 card values

J = Jack

Q = Queen, etc.

D = Diamonds

S = Spades. etc.

Ex. if the user enters QS then your program responds with Queen of Spades

--------------------------------

#include

#include

using namespace std;

//decalring the functions

string getSuit(string suit);

string getRank(string rank);

int main()

{

string card, suit, rank, s, r;

cout << "Enter card in shorthand: ";

cin >> card;

// calling getSuit and getRank functions

suit = getSuit(s);

rank = getRank(r);

cout << rank << " of " << suit << ".";

return 0;

}

//Function definition

string getSuit(string suit)

{

if (suit == "H")

return "Hearts";

if (suit == "S")

return "Spades";

if (suit == "D")

return "Diamond";

if (suit == "C")

return "Clubs";

else return "Invalid suit.";

}

//Function definition

string getRank(string rank)

{

if (rank == "2")

return "2";

else if (rank == "3")

return "3";

else if (rank == "4")

return "4";

else if (rank == "5")

return "5";

else if (rank == "6")

return "6";

else if (rank == "7")

return "7";

else if (rank == "8")

return "8";

else if (rank == "9")

return "9";

else if (rank == "10")

return "10";

else if (rank == "J")

return "Jack";

else if (rank == "Q")

return "Queen";

else if (rank == "K")

return "King ";

else if (rank == "A")

return "Ace";

else

return "Invalid rank.";

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!