c++ programming help!

Status
Not open for further replies.
Joined
Oct 17, 2011
Messages
2
Reaction score
0
Points
1
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);

}
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
It builds fine here but running it gives me a segfault.

By any chance, is this a homework question?
 
OP
J
Joined
Oct 17, 2011
Messages
2
Reaction score
0
Points
1
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!
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
Sorry, we can't provide you with help. Please contact your teacher/professor and/or a teaching assistant.
 
Status
Not open for further replies.

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top