cardGame

cardGame

Closed - This job posting has been filled and work has been completed.

Job Description

Can anyone tell my why I can't run with Microsoft visual studio? And what the errors are? I would also need an header for this program and the classes it has.

// war.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include<iostream>
#include<conio.h>
#include<ctime> //needed for getRand
using namespace std;
//#include"cards.cpp"

int _tmain(int argc, int _TCHAR* argv[])
{
int getRand(); //Get a random number under 52
int rand; //See above
void battle(int, int, int &x, int&y); //Whose card is bigger anyway?
void getWinner(int &a, int &b); //See if player beats computer

const int ALLCARDS = 52;
int split[ALLCARDS] = {0}; //Keeps track of who has what card: 0 is not used, 1 is player, 2 is computer
int i;
int playerScore = 0;
int comScore = 0;
int drip = 1;
int playerCard = 52;
int comCard = 52;
srand((unsigned)time(NULL));

//Gives 1s to player
for(i = 0;i <26;i++){
rand = getRand();
//cout<<rand<<' ';
if(split[rand] == 0)split[rand]=1;
else{
i--;
}
}
//Gives all 0s to computer
for(i = 0;i < ALLCARDS;i++)
if(split[i] == 0)split[i]=2;
//
//start playing war
//

while((playerScore + comScore) != 52){
cout<<"Deal #"<<drip<<endl;

while(split[playerCard] != 1)
playerCard = getRand();
cout<<"\tPlayer has "<<CARD[playerCard]<<" ("<<playerCard<<')'<<endl;
split[playerCard]=0;


while(split[comCard] != 2)
comCard = getRand();
cout<<"\tComputer has "<<CARD[comCard]<<" ("<<comCard<<')'<<endl;
split[comCard]=0;

//distribute and display score
battle(playerCard, comCard, playerScore, comScore);
cout<<"Player score is "<<playerScore<<endl;
cout<<"Computer score is "<<comScore<<endl;

for(i=0;i<ALLCARDS;i++)cout<<split[i]; //debug
cout<<endl; //debug

system("PAUSE");
cout<<endl;
drip += 1;
}
getWinner(playerScore, comScore);
_getch();
return 0;}

int getRand(){
const int DIVISOR = 52;
int result;
result = rand() % DIVISOR;
return result;
}

void battle(int a, int b, int &x, int &y){
while(a > 13)a -=13;
while(b > 13)b -=13;
if(a > b)x += 2;
else if(a == b){
x += 1;
y += 1;
}
else if(a < b)y += 2;
}

void getWinner(int &a, int &b){
if(a > b)
cout<<"\n\nYou win!! ...In this game of chance.";
else
cout<<"\n\nYou lost. Haha.";
}