New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Operating System General OS operation information and support

c++ programming help!


Thread Closed

 
Thread Tools
ji4o90d

 
Member Since: Oct 17, 2011
Posts: 2
ji4o90d is on a distinguished road

ji4o90d is offline
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

 
vansmith's Avatar
 
Member Since: Oct 19, 2008
Location: Toronto
Posts: 18,352
vansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond repute
Mac Specs: 2012 13" MBP (2.5 i5, 8GB)

vansmith is offline
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
ji4o90d

 
Member Since: Oct 17, 2011
Posts: 2
ji4o90d is on a distinguished road

ji4o90d is offline
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

 
vansmith's Avatar
 
Member Since: Oct 19, 2008
Location: Toronto
Posts: 18,352
vansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond repute
Mac Specs: 2012 13" MBP (2.5 i5, 8GB)

vansmith is offline
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 Closed


« Memory Stick Problems | Enable Fullscreen for any application in Lion »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Newbie wanting to learn about Programming Concepts on a Mac c1ph3rtxt OS X - Development and Darwin 7 04-09-2010 01:41 AM
Mackbook or MBP for programming smilemoveon Apple Notebooks 5 02-13-2008 09:55 AM
Mac Programming frewegooh Switcher Hangout 20 05-01-2007 03:32 PM
Need advice on programming. HareshKainth OS X - Development and Darwin 3 10-09-2005 03:33 PM
Programming on the Mac natey OS X - Development and Darwin 4 06-29-2004 07:05 AM

All times are GMT -4. The time now is 03:41 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?