Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

More Books

Students also viewed these Databases questions