Created
February 12, 2012 17:15
-
-
Save sinannar/1809748 to your computer and use it in GitHub Desktop.
its a small stock market game
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* HW03_091044005_PPART_2.c | |
* | |
* CREATED BY :Sinan NAR | |
* CREATING DATE :25/03/2011 | |
* | |
* DESCRIPTION | |
* This code is a source of a game that is a stock market game | |
* two player should be infront of the computer to play these game | |
* and players goals should be make to maximum asset with logically invesment | |
* game will take 12 turns as weeks | |
* | |
* REFERENCES: | |
* [1] 102_HW_03.pdf | |
*/ | |
/*our libraries*/ | |
#include<stdio.h> | |
#include<time.h> | |
/*our constants*/ | |
#define HUNDRED 100.0 | |
#define TWELWE 12 | |
#define ONE 1 | |
#define SEVEN 7 | |
#define FIVE 5 | |
#define ONIGHT 18 | |
#define FIVEON 51 | |
#define TWOFIVE 25 | |
/*our functions protothps*/ | |
double money_to_dollar(double,double); | |
double dollar_to_money(double,double); | |
double money_to_gold(double,double); | |
double gold_to_money(double,double); | |
double money_to_bond(double,double); | |
double bond_to_money(double,double); | |
void show_general_menu(int,int,int,int); | |
void show_player1(double,double,double,double); | |
void show_player2(double,double,double,double); | |
void choosing_menu(void); | |
void buy_menu(void); | |
void sell_menu(void); | |
double total_asset(double,double,int,double,int,double,int); | |
/*start with main functions*/ | |
void main() | |
{ | |
double moneyplayer1=HUNDRED, | |
moneyplayer2=HUNDRED; | |
double goldplayer1=0, | |
goldplayer2=0; | |
double dollarplayer1=0, | |
dollarplayer2=0; | |
double bondplayer1=0, | |
bondplayer2=0; | |
int hafta, | |
choice1, | |
choice2, | |
choice3, | |
choice4; | |
int dolar_kur, | |
bond_kur, | |
gold_kur; | |
int islem; | |
int assetplayer1, | |
assetplayer2; | |
for(hafta=ONE;hafta<=TWELWE;++hafta) | |
{ /*rate of investments*/ | |
dolar_kur=(rand()%SEVEN)+SEVEN; | |
gold_kur=(rand()%FIVE)+ONIGHT; | |
bond_kur=(rand()%FIVEON)+TWOFIVE; | |
/**PLAYER 1**/ | |
do{ system("clear"); | |
/*our menus*/ | |
show_general_menu(hafta,dolar_kur,bond_kur,gold_kur); | |
show_player1(moneyplayer1,goldplayer1,bondplayer1,dollarplayer1); | |
show_player2(moneyplayer2,goldplayer2,bondplayer2,dollarplayer2); | |
choosing_menu(); | |
printf("Player1>"); | |
scanf("%d",&choice1); | |
switch(choice1) | |
{ | |
case 1: //choosing buy and process | |
{ | |
do{ | |
buy_menu(); | |
scanf("%d",&choice2); | |
switch(choice2) | |
{ | |
case 1: //buying dollar and process | |
{ | |
printf("PLEASE ENTER HOW MUCH DOLLAR DO YOU WANT TO BUY\n"); | |
scanf("%d",&islem); | |
while(moneyplayer1<dollar_to_money(dolar_kur,islem)) | |
{ | |
printf("YOU DONT HAVE ENOUGH MONEY\n"); | |
printf("PLEASE ENTER HOW MUCH DOLLAR DO YOU WANT TO BUY\n"); | |
scanf("%d",&islem); | |
} | |
moneyplayer1=moneyplayer1-dollar_to_money(dolar_kur,islem); | |
dollarplayer1=dollarplayer1+islem; | |
} | |
break; | |
case 2: //buying gold and process | |
{ | |
printf("PLEASE ENTER HOW MUCH GOLD DO YOU WANT TO BUY\n"); | |
scanf("%d",&islem); | |
while(moneyplayer1<gold_to_money(gold_kur,islem)) | |
{ | |
printf("YOU DONT HAVE ENOUGH MONEY\n"); | |
printf("PLEASE ENTER HOW MUCH GOLD DO YOU WANT TO BUY\n"); | |
scanf("%d",&islem); | |
} | |
moneyplayer1=moneyplayer1-gold_to_money(gold_kur,islem); | |
goldplayer1=goldplayer1+islem; | |
} | |
break; | |
case 3: //buying bond and process | |
{ | |
printf("PLEASE ENTER HOW MUCH BOND DO YOU WANT TO BUY\n"); | |
scanf("%d",&islem); | |
while(moneyplayer1<bond_to_money(bond_kur,islem)) | |
{ | |
printf("YOU DONT HAVE ENOUGH MONEY\n"); | |
printf("PLEASE ENTER HOW MUCH BOND DO YOU WANT TO BUY\n"); | |
scanf("%d",&islem); | |
} | |
moneyplayer1=moneyplayer1-bond_to_money(bond_kur,islem); | |
bondplayer1=bondplayer1+islem; | |
} | |
break; | |
} | |
}while(choice2!=4); //end of do while loop for buying | |
} | |
break; | |
case 2: //choosing sell ad process | |
{ | |
do{ | |
buy_menu(); | |
scanf("%d",&choice2); | |
switch(choice2) | |
{ | |
case 1: //selling dollar and process | |
{ | |
printf("PLEASE ENTER HOW MUCH DOLLAR DO YOU WANT TO SELL\n"); | |
scanf("%d",&islem); | |
while(dollarplayer1<islem) | |
{ | |
printf("YOU DONT HAVE ENOUGH DOLLAR\n"); | |
printf("PLEASE ENTER HOW MUCH DOLLAR DO YOU WANT TO SELL\n"); | |
scanf("%d",&islem); | |
} | |
dollarplayer1=dollarplayer1-islem; | |
moneyplayer1=moneyplayer1+dollar_to_money(dolar_kur,islem); | |
} | |
break; | |
case 2: //selling gold and process | |
{ | |
printf("PLEASE ENTER HOW MUCH GOLD DO YOU WANT TO SELL\n"); | |
scanf("%d",&islem); | |
while(goldplayer1<islem) | |
{ | |
printf("YOU DONT HAVE ENOUGH GOLD\n"); | |
printf("PLEASE ENTER HOW MUCH GOLD DO YOU WANT TO SELL\n"); | |
scanf("%d",&islem); | |
} | |
goldplayer1=goldplayer1-islem; | |
moneyplayer1=moneyplayer1+gold_to_money(gold_kur,islem); | |
} | |
break; | |
case 3: //selling bond and process | |
{ | |
printf("PLEASE ENTER HOW MUCH BOND DO YOU WANT TO SELL\n"); | |
scanf("%d",&islem); | |
while(bondplayer1<islem) | |
{ | |
printf("YOU DONT HAVE ENOUGH BOND\n"); | |
printf("PLEASE ENTER HOW MUCH BOND DO YOU WANT TO SELL\n"); | |
scanf("%d",&islem); | |
} | |
bondplayer1=bondplayer1-islem; | |
moneyplayer1=moneyplayer1+bond_to_money(bond_kur,islem); | |
} | |
break; | |
} | |
}while(choice2!=4); //end of do while loop for selling | |
} | |
break; | |
} | |
}while(choice1!=3); //end of do while loop for player 1 | |
/**PLAYER 2**/ | |
system("clear"); | |
do{ /*show menus*/ | |
show_general_menu(hafta,dolar_kur,bond_kur,gold_kur); | |
show_player1(moneyplayer1,goldplayer1,bondplayer1,dollarplayer1); | |
show_player2(moneyplayer2,goldplayer2,bondplayer2,dollarplayer2); | |
choosing_menu(); | |
printf("Player2>"); | |
scanf("%d",&choice3); | |
switch(choice3) | |
{ | |
case 1: //choosing buy and process | |
{ | |
do{ | |
buy_menu(); | |
scanf("%d",&choice4); | |
switch(choice4) | |
{ | |
case 1: //buying dollar and process | |
{ | |
printf("PLEASE ENTER HOW MUCH DOLLAR DO YOU WANT TO BUY\n"); | |
scanf("%d",&islem); | |
while(moneyplayer1<dollar_to_money(dolar_kur,islem)) | |
{ | |
printf("YOU DONT HAVE ENOUGH MONEY\n"); | |
printf("PLEASE ENTER HOW MUCH DOLLAR DO YOU WANT TO BUY\n"); | |
scanf("%d",&islem); | |
} | |
moneyplayer2=moneyplayer2-dollar_to_money(dolar_kur,islem); | |
dollarplayer2=dollarplayer2+islem; | |
} | |
break; | |
case 2: //buying gold and process | |
{ | |
printf("PLEASE ENTER HOW MUCH GOLD DO YOU WANT TO BUY\n"); | |
scanf("%d",&islem); | |
while(moneyplayer2<gold_to_money(gold_kur,islem)) | |
{ | |
printf("YOU DONT HAVE ENOUGH MONEY\n"); | |
printf("PLEASE ENTER HOW MUCH GOLD DO YOU WANT TO BUY\n"); | |
scanf("%d",&islem); | |
} | |
moneyplayer2=moneyplayer2-gold_to_money(gold_kur,islem); | |
goldplayer2=goldplayer2+islem; | |
} | |
break; | |
case 3: //buying bond and process | |
{ | |
printf("PLEASE ENTER HOW MUCH BOND DO YOU WANT TO BUY\n"); | |
scanf("%d",&islem); | |
while(moneyplayer2<bond_to_money(bond_kur,islem)) | |
{ | |
printf("YOU DONT HAVE ENOUGH MONEY\n"); | |
printf("PLEASE ENTER HOW MUCH BOND DO YOU WANT TO BUY\n"); | |
scanf("%d",&islem); | |
} | |
moneyplayer2=moneyplayer2-bond_to_money(bond_kur,islem); | |
bondplayer2=bondplayer2+islem; | |
} | |
break; | |
} | |
}while(choice4!=4); // end of do while loops for buying | |
} | |
break; | |
case 2: //choosing sell and process | |
{ | |
do{ | |
buy_menu(); | |
scanf("%d",&choice4); | |
switch(choice4) | |
{ | |
case 1: //selling dollar and process | |
{ | |
printf("PLEASE ENTER HOW MUCH DOLLAR DO YOU WANT TO SELL\n"); | |
scanf("%d",&islem); | |
while(dollarplayer2<islem) | |
{ | |
printf("YOU DONT HAVE ENOUGH DOLLAR\n"); | |
printf("PLEASE ENTER HOW MUCH DOLLAR DO YOU WANT TO SELL\n"); | |
scanf("%d",&islem); | |
} | |
dollarplayer2=dollarplayer2-islem; | |
moneyplayer2=moneyplayer2+dollar_to_money(dolar_kur,islem); | |
} | |
break; | |
case 2: //selling gold and process | |
{ | |
printf("PLEASE ENTER HOW MUCH GOLD DO YOU WANT TO SELL\n"); | |
scanf("%d",&islem); | |
while(goldplayer2<islem) | |
{ | |
printf("YOU DONT HAVE ENOUGH GOLD\n"); | |
printf("PLEASE ENTER HOW MUCH GOLD DO YOU WANT TO SELL\n"); | |
scanf("%d",&islem); | |
} | |
goldplayer2=goldplayer2-islem; | |
moneyplayer2=moneyplayer2+gold_to_money(gold_kur,islem); | |
} | |
break; | |
case 3: //selling bond and process | |
{ | |
printf("PLEASE ENTER HOW MUCH BOND DO YOU WANT TO SELL\n"); | |
scanf("%d",&islem); | |
while(bondplayer2<islem) | |
{ | |
printf("YOU DONT HAVE ENOUGH BOND\n"); | |
printf("PLEASE ENTER HOW MUCH BOND DO YOU WANT TO SELL\n"); | |
scanf("%d",&islem); | |
} | |
bondplayer2=bondplayer2-islem; | |
moneyplayer2=moneyplayer2+bond_to_money(bond_kur,islem); | |
} | |
break; | |
} | |
}while(choice4!=4); //end of do while loops for selling | |
} | |
break; | |
} | |
}while(choice3!=3); //end of do while loops for player 2 | |
system("clear"); | |
// process of the calculating assets of boyt player1 and player2 | |
assetplayer1=total_asset(moneyplayer1,dollarplayer1,dolar_kur,bondplayer1,bond_kur,goldplayer1,gold_kur); | |
assetplayer2=total_asset(moneyplayer2,dollarplayer2,dolar_kur,bondplayer2,bond_kur,goldplayer2,gold_kur); | |
//end of the game | |
if(assetplayer1>assetplayer2) | |
{ | |
printf("\n\n\tWINNER IS THE PLAYER 1\n"); | |
} | |
else if(assetplayer1<assetplayer2) | |
{ | |
printf("\n\n\tWINNER IS THE PLAYER 2\n"); | |
} | |
else printf("\n\n\tTHERE IS NO WINNER\n"); | |
} | |
} | |
/** FUNCTIONS **/ | |
//this function get some double and int value and calculate the total assets | |
double total_asset(double money,double dolar,int dolar_kur,double bond,int bond_kur,double gold,int gold_kur) | |
{ | |
double total; | |
total=money+(dolar*dolar_kur)+(bond*bond_kur)+(gold*gold_kur); | |
return total; | |
} | |
//show menu just input as the week and value of investments | |
void show_general_menu(int hafta,int dolar_kur,int bond_kur,int gold_kur) | |
{ | |
printf("WEEK :%d \n",hafta); | |
printf("-----------\n"); | |
printf("DOLLAR :%d\n",dolar_kur); | |
printf("GOLD :%d\n",gold_kur); | |
printf("BOND :%d\n",bond_kur); | |
printf("-----------\n"); | |
} | |
//show asset of player 1 and inputs are money gold bond and dollar of player1 | |
void show_player1(double moneyplayer1,double goldplayer1,double bondplayer1,double dollarplayer1) | |
{ | |
printf("--PLAYER 1--\n"); | |
printf("Money :%.2f\n",moneyplayer1); | |
printf("Gold :%.2f\n",goldplayer1); | |
printf("Bond :%.2f\n",bondplayer1); | |
printf("Dollar :%.2f\n",dollarplayer1); | |
printf("------------\n"); | |
} | |
//show asset of player 2 and inputs are money gold bond and dollar of player2 | |
void show_player2(double moneyplayer2,double goldplayer2,double bondplayer2,double dollarplayer2) | |
{ | |
printf("--PLAYER 2--\n"); | |
printf("Money :%.2f\n",moneyplayer2); | |
printf("Gold :%.2f\n",goldplayer2); | |
printf("Bond :%.2f\n",bondplayer2); | |
printf("Dollar :%.2f\n",dollarplayer2); | |
printf("------------\n"); | |
} | |
//choosing menu no input | |
void choosing_menu(void) | |
{ | |
printf("1.BUY\n"); | |
printf("2.SELL\n"); | |
printf("3.PASS\n"); | |
} | |
//buying menu no input | |
void buy_menu(void) | |
{ | |
printf("1.DOLLAR\n"); | |
printf("2.GOLD\n"); | |
printf("3.BOND\n"); | |
printf("4.previous\n menu"); | |
} | |
//selling menu no input | |
void sell_menu(void) | |
{ | |
printf("1.DOLLAR\n"); | |
printf("2.GOLD\n"); | |
printf("3.BOND\n"); | |
printf("4.previous\n menu"); | |
} | |
/** HERE IS THE FUNCTIONS CALCULATE THE INVESTMENT TYPE OF THE OTHERS | |
input as two double value and output with return also as a double value | |
note:we may not use some of them but starting of the program i will write it all | |
**/ | |
double money_to_dollar(double dolar_kur,double islem)//money cinsinden girilir | |
{ | |
return islem/dolar_kur; | |
} | |
double dollar_to_money(double dolar_kur,double islem)//dolar cinsinden girilir | |
{ | |
return islem*dolar_kur; | |
} | |
double money_to_gold(double gold_kur,double islem)//money cinsinden girilir | |
{ | |
return islem/gold_kur; | |
} | |
double gold_to_money(double gold_kur,double islem)//gold cinsinden girilir | |
{ | |
return islem*gold_kur; | |
} | |
double money_to_bond(double bond_kur,double islem)//money cinsinden girilir | |
{ | |
return islem/bond_kur; | |
} | |
double bond_to_money(double bond_kur,double islem)//bond cinsinden girilir | |
{ | |
return islem*bond_kur; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment