Outputting Card Notations

Hi there noob here who for an assignment is trying to make a program where you input a card notation and the full name of the card comes out.

For example,

"4H" --> Four of Hearts

"QS" --> Queen of Spades

Now I can do it the easy way where I do 52 if statements and have each individual input correlate to 1 single output. Or i can use substr and legnth functions to make it easier. So does anyone have any info on how I can use substr and length functions to make this easier?

Thank you.

Here is a screenshot of what I have right now (the easy way):

https://i.gyazo.com/fd088dbbb1e3a2d1604185853b82370e.png

But I want to know how to make it so I don't copy paste this 52 times.
Last edited on
You could read each char (1st) as 2-10, J,Q,K,A as "Two-Ten" and (2nd) C, D, H or S as "of Clubs" which would save 3/4 of the CPU work as well as typing.
Last edited on
I would do something like have two input statements one int, and one char. Then make an array of strings with the words "ace, two, three, four,.... queen, king". Then do a for loop through them depending on the int variable entered. And then I would take the char variable convert it to an int (subtract whatever number to make it 0-4) and do the same thing with another array of strings "hearts, clubs...".
You can use a for loop and a string array and they will help you complete the task.
Topic archived. No new replies allowed.