Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7636357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:39:26+00:00 2026-05-31T07:39:26+00:00

I don’t understand my problem here. My List on taking the values of the

  • 0

I don’t understand my problem here. My List on taking the values of the faction and the number seems right. But, there is a problem with my output. Gives me only numbers and no letters to show in what faction they’re in.

The statements that are printing numbers are at the bottom, like this one:

cout << "Your first Card is "
     << numberBoxListHead_ptr->getNumber()
     << factionHead_ptr->getLetter()
     << endl;

Here is the full code:

#include <iostream>
#include <conio.h>
using namespace std;

//The Class where the List depends on it.
class NumberBox
{
private:

    int number;
    char letter;

public:

    NumberBox *next_ptr;
    void setNumber(int number)
    {
        this->number = number;
    }

    void setLetter(char letter)
    {
        this->letter = letter;
    }


    int getNumber()
    {
        return number;
    }

    char getLetter()
    {
        return letter;
    }
};

int main()
{
    int number[4];
    char faction[4];

    NumberBox *factionHead_ptr = new NumberBox();
    NumberBox *factionBody1_ptr = new NumberBox();
    NumberBox *factionBody2_ptr = new NumberBox();
    NumberBox *factionBody3_ptr = new NumberBox();
    NumberBox *factionTail_ptr = new NumberBox();

    NumberBox *numberBoxListHead_ptr = new NumberBox();
    NumberBox *numberBoxListBody1_ptr = new NumberBox();
    NumberBox *numberBoxListBody2_ptr = new NumberBox();
    NumberBox *numberBoxListBody3_ptr = new NumberBox();
    NumberBox *numberBoxListTail_ptr = new NumberBox();

    cout << "Please give the number for the first Card" << endl;
    cin >> number[0];
    if(number[0] > 0 && number[0] < 13)
    {
        numberBoxListHead_ptr->setNumber(number[0]); /* <--- Setting for the first input, which is the number */
    }
    else
    {
        cout << " Invalid " << endl;
        exit(1);
    }
    cout << "Please Give the faction for the first Card" << endl;
    cin >> faction[0];
    if(faction [0] == 's' || faction [0] == 'c' || faction [0] == 'h' || faction [0] == 'd')
    {
        if(faction[0] == 's')
        {
            factionHead_ptr->setLetter('s');
        }
        else if(faction[0] == 'c')
        {
            factionHead_ptr->setLetter('c');
        }
        else if(faction[0] == 'h')
        {
            factionHead_ptr->setLetter('h');
        }
        else if(faction[0] == 'd')
        {
            factionHead_ptr->setLetter('d');
        }
    }
    else
    {
        cout << "Invalid" << endl;
        exit(1);
    }


    cout << "Please give the number for the Second Card" << endl;
    cin >> number[1];
    if(number[1] > 0 && number[1] < 13)
    {
        numberBoxListBody1_ptr->setNumber(number[1]); /* <--- Setting for the second input, which is the number */
    }
    else
    {
        cout << " Invalid " << endl;
        exit(1);
    }
    cout << "Please Give the faction for the second Card" << endl;
    cin >> faction[1];
    if(faction[1] == 's' || faction[1] == 'c' || faction [1] == 'h' || faction [1] == 'd')
    {
        if(faction[1] == 's')
        {
            factionHead_ptr->setLetter('s');
        }
        else if(faction[1] == 'c')
        {
            factionHead_ptr->setLetter('c');
        }
        else if(faction[1] == 'h')
        {
            factionHead_ptr->setLetter('h');
        }
        else if(faction[1] == 'd')
        {
            factionHead_ptr->setLetter('d');
        }
    }
    else
    {
        cout << "Invalid" << endl;
        exit(1);
    }
    cout << "Please give the number for the Third Card" << endl;
    cin >> number[2];
    if(number[2] > 0 && number[2] < 13)
    {
        numberBoxListBody2_ptr->setNumber(number[2]); /* <--- Setting for the third input, which is the number */
    }
    else
    {
        cout << " Invalid " << endl;
        exit(1);
    }
    cout << "Please Give the faction for the Third Card" << endl;
    cin >> faction[2];
    if(faction[2] == 's' || faction[2] == 'c' || faction [2] == 'h' || faction [2] == 'd')
    {
        if(faction[2] == 's')
        {
            factionHead_ptr->setLetter('s');
        }
        else if(faction[2] == 'c')
        {
            factionHead_ptr->setLetter('c');
        }
        else if(faction[2] == 'h')
        {
            factionHead_ptr->setLetter('h');
        }
        else if(faction[2] == 'd')
        {
            factionHead_ptr->setLetter('d');
        }
    }
    else
    {
        cout << "Invalid" << endl;
        exit(1);
    }
    cout << "Please give the number for the fourth Card" << endl;
    cin >> number[3];
    if(number[3] > 0 && number[3] < 13)
    {
        numberBoxListBody3_ptr->setNumber(number[3]); /* <--- Setting for the fourth input, which is the number */
    }
    else
    {
        cout << " Invalid " << endl;
        exit(1);
    }
    cout << "Please Give the faction for the fourth Card" << endl;
    cin >> faction[3];
    if(faction[3] == 's' || faction[3] == 'c' || faction [3] == 'h' || faction [3] == 'd')
    {
        if(faction[3] == 's')
        {
            factionHead_ptr->setLetter('s');
        }
        else if(faction[3] == 'c')
        {
            factionHead_ptr->setLetter('c');
        }
        else if(faction[3] == 'h')
        {
            factionHead_ptr->setLetter('h');
        }
        else if(faction[3] == 'd')
        {
            factionHead_ptr->setLetter('d');
        }
    }
    else
    {
        cout << "Invalid" << endl;
        exit(1);
    }
    cout << "Please give the number for the Fifth Card" << endl;
    cin >> number[4];
    if(number[4] > 0 && number[4] < 13)
    {
        numberBoxListTail_ptr->setNumber(number[4]); /* <--- Setting for the fifth input, which is the number */
    }
    else
    {
        cout << " Invalid " << endl;
        exit(1);
    }

    cout << "Please Give the faction for the fifth Card" << endl;
    cin >> faction[4];
    if(faction[4] == 's' || faction[4] == 'c' || faction [4] == 'h' || faction [4] == 'd')
    {
        if(faction[4] == 's')
        {
            factionHead_ptr->setLetter('s');
        }
        else if(faction[4] == 'c')
        {
            factionHead_ptr->setLetter('c');
        }
        else if(faction[4] == 'h')
        {
            factionHead_ptr->setLetter('h');
        }
        else if(faction[4] == 'd')
        {
            factionHead_ptr->setLetter('d');
        }
    }
    else
    {
        cout << "Invalid" << endl;
        exit(1);
    }

    //This would be the list for the value of the card.

    numberBoxListHead_ptr->next_ptr = numberBoxListBody1_ptr; /* <--- From Head to Body1 */
    numberBoxListBody1_ptr->next_ptr = numberBoxListBody2_ptr; /* <--- From Body1 to Body2 */
    numberBoxListBody2_ptr->next_ptr = numberBoxListBody3_ptr; /* <--- From Body2 to Body3 */
    numberBoxListBody3_ptr->next_ptr = numberBoxListTail_ptr; /* <--- From Body3 to BodyTail */

    //This Would be the list for the faction of the card.

    factionHead_ptr->next_ptr = factionBody1_ptr; /* <--- From Head to Body1 */
    factionBody1_ptr->next_ptr = factionBody2_ptr; /* <--- From Body1 to Body2 */
    factionBody2_ptr->next_ptr = factionBody3_ptr; /* <--- From Body2 to Body3 */
    factionBody3_ptr->next_ptr = factionTail_ptr; /* <--- From Body3 to BodyTail */

    int counter;
    for(counter = 0; counter < 4; counter++)
    {
        if(counter == 0)
        {
            cout << "Your first Card is " << numberBoxListHead_ptr->getNumber() << factionHead_ptr->getLetter() << endl;
        }
        if(counter == 1)
        {
            cout << "Your Second Card is " << numberBoxListBody1_ptr->getNumber() << factionBody1_ptr->getLetter() << endl;
        }
        if(counter == 2)
        {
            cout << "Your third Card is " << numberBoxListBody2_ptr->getNumber() << factionBody2_ptr->getLetter() << endl;
        }
        if(counter == 3)
        {
            cout << "Your fourth Card is " << numberBoxListBody3_ptr->getNumber() << factionBody3_ptr->getLetter() << endl;
        }
        if(counter == 4)
        {
            cout << "Your fifth Card is " << numberBoxListTail_ptr->getNumber() << factionTail_ptr->getLetter() << endl;
        }
    }
    getch();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:39:27+00:00Added an answer on May 31, 2026 at 7:39 am
    int getLetter()
    

    This is wrong in this case. letter is a char, make sure you return a char if you want it to be printed as a letter.

    char getLetter() { ... }
    

    If you return an int, std::cout will print it numerical value just like it does for the card rank. If you return a char, it will print the corresponding character, not its numerical value.

    (Your code needs a serious refactoring work. Make functions to handle inputting the suit, and the rank, and reuse those functions. Then figure out how to do a loop to read the four cards.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know if I worded the question right, but basically what I want to
Don't know if this is the right place to ask this, but I will
Don't ask why, but is there any way to suppress a failed linking error?
Don't know if this is an eclipse specific problem but whenever I declare a
Don't think there's much to say, here's my code for (int i = 0;
Don't ask how I got there, but I was playing around with some masking,
Don't need to do this right now but thinking about the future... What would
don't know better title for this, but here's my code. I have class user
Don't know a better title but here is what im trying to do. I
(Don't know if this is strictly on-topic, but I don't see any better Stack

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.