Okay i am apparently having problems on understanding exactly how string works. The problem im having is I get an error at the part where it assigns the cards. Please help me! Much appreciated!
#include "stdafx.h"
#include <string>
#include <time.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string getsuit();
string getcard();
string card[6];
srand(time(0));
int c;
system("cls");
cout<<"Press end to exit.\n\nWelcome to the card game!\nPress 'h' to deal!\n";
c=_getch();
if(c=='h'){
//this part
card[1]=getcard()+getsuit();
card[2]=getcard()+getsuit();
card[3]=getcard()+getsuit();
card[4]=getcard()+getsuit();
card[5]=getcard()+getsuit();
cout<<"\n"<<card[1]<<"\n"
<<"\n"<<card[2]<<"\n"
<<"\n"<<card[3]<<"\n"
<<"\n"<<card[4]<<"\n"
<<"\n"<<card[5]<<"\n";
}
system("pause");
return 0;
}
string getsuit(){
int c;
c=(1 + rand() % (4));
switch(c){
case 1:
return "Hearts";
break;
case 2:
return "Diamonds";
break;
case 3:
return "Spades";
break;
case 4:
return "Clubs";
break;
}
}
string getcard(){
int c;
c=(1+ rand() % (52));
switch(c){
case 1:
return "Ace";
break;
case 2:
return "Two";
break;
case 3:
return "Three";
break;
case 4:
return "Four";
break;
case 5:
return "Five";
break;
case 6:
return "Six";
break;
case 7:
return "Seven";
break;
case 8:
return "Eight";
break;
case 9:
return "Nine";
break;
case 10:
return "Ten";
break;
case 11:
return "Jack";
break;
case 12:
return "Queen";
break;
case 13:
return "King";
break;
}
}
Thanks you alls!