Results 1 to 4 of 4
  1. #1
    c++ programming help!

    Member Since
    Oct 17, 2011
    Posts
    2
    c++ programming help!
    I'm having trouble with this program. Whenever I try to compile, it will not work and it won't say why. Any tips will help.

    #include <iostream>
    #include <ctime>
    #include <cstdlib>

    using namespace std;

    string cardName(int card)
    {
    if (card == 0)
    return "Ace";
    else if (card == 10)
    return "Jack";
    else if (card == 11)
    return "Queen";
    else if (card == 12)
    return "King";
    else
    cout << card;
    }

    string findSuit(int card)
    {
    int Suit = card % 13 ;
    if (Suit == 0)
    return " of Clubs";
    else if (Suit == 1)
    return " of Diamonds";
    else if (Suit == 2)
    return "of Hearts";
    else
    return " of Spades";
    }


    int main()
    {
    srand(time(NULL));

    int playerCard1, playerCard2;

    playerCard1 = rand() % 13;
    playerCard2 = rand() % 13;

    cout << "Your first card is: ";
    cout << cardName(playerCard1);
    cout << findSuit(playerCard1) << " and ";

    cout << "your second card is: ";
    cout << cardName(playerCard2);
    cout << findSuit(playerCard2);

    }

  2. #2
    c++ programming help!
    vansmith's Avatar
    Member Since
    Oct 19, 2008
    Location
    Toronto
    Posts
    19,395
    Specs:
    2012 13" MBP (2.5 i5, 8GB)
    It builds fine here but running it gives me a segfault.

    By any chance, is this a homework question?
    Important Links: Community Guidelines : Use the reputation system if you've been helped.
    M-F Blog :: Write for the blog
    Writing a Quality Post

  3. #3
    c++ programming help!

    Member Since
    Oct 17, 2011
    Posts
    2
    Yes, and the whole project is due tomorrow. I know i should not be doing this but there is literally no where else that could help me. If you see anything that you see wrong in this section of my program, please tell me. thanks!

  4. #4
    c++ programming help!
    vansmith's Avatar
    Member Since
    Oct 19, 2008
    Location
    Toronto
    Posts
    19,395
    Specs:
    2012 13" MBP (2.5 i5, 8GB)
    Sorry, we can't provide you with help. Please contact your teacher/professor and/or a teaching assistant.
    Important Links: Community Guidelines : Use the reputation system if you've been helped.
    M-F Blog :: Write for the blog
    Writing a Quality Post

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 05-29-2012, 05:32 PM
  2. Programming
    By Jonablink23 in forum iOS Development
    Replies: 1
    Last Post: 10-20-2011, 02:50 PM
  3. Programming in C
    By Macman95 in forum OS X - Development and Darwin
    Replies: 13
    Last Post: 10-14-2009, 07:28 PM
  4. C programming
    By juco in forum OS X - Apps and Games
    Replies: 6
    Last Post: 05-19-2006, 06:52 PM
  5. programming
    By kakosc in forum Schweb's Lounge
    Replies: 6
    Last Post: 01-09-2004, 11:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •