Hello, I am teaching myself to program, and as part of a project I am working on, I used this code to create a deck of cards and then randomly move cards to 2 hands.
Hitting run in XCode says there are no errors.
However, when i compile this in XCode, it gives me:
I looked into the debugger and saw it to be way over my head. Any help?
Code:
#include <stdlib.h>
#include <iostream>
#include <time.h>
#include <string>
#include <vector>
using namespace std;
int i,l,j;
string Deck [52] = {"Ace of Spades", "Two of Spades", "Three of Spades", "Four of Spades",
"Five of Spades", "Six of Spades", "Seven of Spades", "Eight of Spades",
"Nine of Spades", "Ten of Spades", "Jack of Spades", "Queen of Spades",
"King of Spades",
"Ace of Hearts", "Two of Hearts", "Three of Hearts", "Four of Hearts",
"Five of Hearts", "Six of Hearts", "Seven of Hearts", "Eight of Hearts",
"Nine of Hearts", "Ten of Hearts", "Jack of Hearts", "Queen of Hearts",
"King of Hearts",
"Ace of Clubs", "Two of Clubs", "Three of Clubs", "Four of Clubs",
"Five of Clubs", "Six of Clubs", "Seven of Clubs", "Eight of Clubs",
"Nine of Clubs", "Ten of Clubs", "Jack of Clubs", "Queen of Clubs",
"King of Clubs",
"Ace of Diamonds", "Two of Diamonds", "Three of Diamonds", "Four of Diamonds",
"Five of Diamonds", "Six of Diamonds", "Seven of Diamonds", "Eight of Diamonds",
"Nine of Diamonds", "Ten of Diamonds", "Jack of Diamonds", "Queen of Diamonds",
"King of Diamonds"}; //the starting deck
int main ()
{
int n,m;
string k;
vector<string> first;
for (j=0; j<52; j++) {
first.push_back (Deck[j]);//turning the deck into a vector
}
vector<string> Hand1 ;
vector<string> Hand2 ;
srand ( time(NULL) );
while (first.size()>0)
{
n = rand() % (first.size()-1); //puts a card into Hand1, then deletes it from the deck
first.at(n)=k;
Hand1.push_back (k);
first.erase (first.begin()+(n-1));
m = rand() % (first.size()-1); //ditto with Hand2
first.at(m)=k;
Hand2.push_back (k);
first.erase (first.begin()+(m-1));
}
cout << "The contents of Hand 1 is:"; //outputs the contents of each hand
for (i=0; i < Hand1.size(); i++){
cout << " " << Hand1[i];}
cout << "/n.The Contents of Hand 2 is:";
for (l=0; l < Hand2.size(); l++) {
cout<< " " << Hand2[l];}
return 0;
}
However, when i compile this in XCode, it gives me:
Code:
Program received signal: EXC_BAD_ACCESS.
sharedlibrary apply-load-rules all