Day One:
Information:
Functions:
#include <stdio.h>
#include <stdlib.h>
void main()
{
printf("Hello Chinchilla\n") ;
while (1) ;
}
This is my first example that I did (this could come in handy sometime)
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int max_value;
void PickANumber()
{
int target;
int guess=-1;
char throw_away;
int score=0;
int par=0;
int temp;
srand ((unsigned int)time(0));
target = rand()%max_value;
target = rand()%max_value;
temp = max_value;
while(max_value > 1)
{
max_value= max_value/2;
par = par+1;
}
while (guess != target)
{
printf(" Enter a number:");
scanf("%i%c",&guess,&throw_away);
score=score+1;
if( guess<target )
{
printf("Too low, try again");
}
if( guess>target )
{
printf("Too high, try again");
}
if( guess == target)
{
printf("You win the game!\n");
}
}
printf("You guessed the right answer in %i guesses!",score);
if ( score < par)
{
printf("\n\nYou are awesome!");
}
if (score > par)
{
printf("\n\nYou have work to do!");
}
if (score == par)
{
printf("\n\nYou are average.");
}
//printf("You entered %i\n", guess);
// 7 is the value of my_first_var
}
void main()
{
char choice='y';
char throw_away;
printf("What is the maximum number that you want to use?");
scanf("%i%c",&max_value,&throw_away);
while(choice == 'y')
{
PickANumber();
printf("\n\nWould you like to play again (y/n)?");
scanf("%c%c",&choice,&throw_away);
}
//while (1);
}
Day Two:
#include <stdio.h>
#include <stdlib.h>
void main ()
{
char throw_away;
int choice;
int number;
choice=0;
printf("Choose a niumber between 10 and 20");
scanf("%i%c",&number,&throw_away);
while ( number != choice)
{
printf("%i ",choice+1);
choice = choice +1;
}
while (1);
}
This was my calculator program:
#include <stdio.h>
#include <stdlib.h>
void main()
{
int numberone;
int numbertwo;
char throw_away;
char function;
numberone= -1;
numbertwo= -1;
printf("Enter a number");
scanf("%i%c", &numberone,&throw_away);
printf("Enter another number");
scanf("%i%c", &numbertwo,&throw_away);
printf("What would you like to do with the number that you picked? (+ - * /)");
scanf("%c%c", &function,&throw_away);
if (function == '+')
{
printf("%i ",numberone+numbertwo);
}
if (function== '-')
{
printf("%i ", numberone-numbertwo);
}
if (function== '*')
{
printf("%i ", numberone*numbertwo);
}
if (function== '/')
{
printf("%i ",numberone/numbertwo);
}
while (1);
}
This was my Blackjack program:
#include <stdio.h>
#include <stdlib.h>
int deck[52];
void InitDeck()
{
int count;
for(count=0; count < 52; count = count+1)
{
deck[count] = count;
}
}
void PrintCard(int card_number)
{
int suit = deck[card_number]/13;
int value = deck[card_number]%13+1;
if(value == 1)
printf("\nA%c ",3+suit);
else if (value == 10)
printf("\nT%c ", 3+suit);
else if (value == 11)
printf("\nJ%c ", 3+suit);
else if (value == 12)
printf("\nQ%c ", 3+suit);
else if (value == 13)
printf("\nK%c ", 3+suit);
else
printf("%i%c ", value,3+suit);
}
void main()
{
int i;
InitDeck();
for(i=0; i < 52; i = i++)
{
PrintCard(i);
}
while (1);
}
Day Three:
So far:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int deck[52];
int hand[2][11];
void InitDeck()
{
int count;
for(count=0; count < 52; count = count+1)
{
deck[count] = count;
}
}
void InitHand(int hand_number)
{
int card;
for (card =0; card < 11; card = card +1)
{
hand[hand_number][card] = -1;
}
//hand[ hand_number][0] = -1;
//hand[ hand_number][1] = -1;
//hand[ hand_number][2] = -1;
//hand[ hand_number][3] = -1;
//hand[ hand_number][4] = -1;
//hand[ hand_number][5] = -1;
//hand[ hand_number][6] = -1;
//hand[ hand_number][7] = -1;
//hand[ hand_number][8] = -1;
//hand[ hand_number][9] = -1;
//hand[ hand_number][10] = -1;
}
void PrintCard(int card_number)
{
int suit = deck[card_number]/13;
int value = deck[card_number]%13+1;
if(value == 1)
printf("A%c ",3+suit);
else if (value == 10)
printf("T%c ", 3+suit);
else if (value == 11)
printf("J%c ", 3+suit);
else if (value == 12)
printf("Q%c ", 3+suit);
else if (value == 13)
printf("K%c ", 3+suit);
else
printf("%i%c ", value,3+suit);
}
int GetValue(int card_number)
{
int value = deck[card_number]%13+1;
if(value> 10)
{
value = 10;
}
return value;
//deck[card_index];
}
int GetHandValue(int hand_number)
{
int c;
int hand_value = 0;
for(c=0;c<11;c++)
{
if(hand[hand_number][c]>=0 && hand[hand_number][c] <=51)
{
hand_value = hand_value + GetValue(hand[hand_number][c]);
}
}
return hand_value;
}
void PrintHand(int hand_number)
{
int c;
int hand_value;
hand_value = 0;
for(c=0;c<11;c++)
{
if(hand[hand_number][c] >= 0 && hand[hand_number][c] <=51)
{
PrintCard(hand[hand_number][c]);
hand_value = hand_value + GetValue(hand[hand_number][c]);
}
}
printf("%i\n",hand_value);
}
int random(int min, int max)
{
int rval;
int range;
range = max - min +1;
rval = rand() % range;
rval = rval + min;
return rval;
}
void main()
{
InitDeck();
InitHand(0);
InitHand(1);
srand( (unsigned) time(0));
char option [64];
char h [64];
char s[64];
int player_count = 0;
int dealer_count = 0;
hand[1][0] = random(0,51);
player_count= player_count + 1;
hand[0][0] = random(0,51);
dealer_count= dealer_count + 1;
hand[1][1] = random(0,51);
player_count= player_count + 1;
hand[0][1] = random(0,51);
dealer_count= dealer_count + 1;
printf("Dealer:\n");
PrintHand(0);
printf("Player:\n");
PrintHand(1);
printf("(h)it or (s)tay");
gets(option);
while(option[0] == 'h')
{
hand[1][player_count] = random(0,51);
player_count= player_count + 1;
PrintHand(1);
printf("Would you like to (h)it or (s)tay?");
gets(option);
if(GetHandValue(1) > 21)
{
option[0]='s';
printf("You lose");
}
else
{
option[0]= 's';
printf("You lose");
}
while (GetHandValue(0) <= 17)
{
printf("Dealer:\n");
hand[0][dealer_count] = random(0,51);
dealer_count= dealer_count + 1;
PrintHand(0);
}
}
//hand[1][2] = random(0,51);
//hand[0][2] = random(0,51);
//gets(option);
//printf("(H)it or (S)tay?");
//hand[1][3] = random(0,51);
//hand[0][3] = random(0,51);
//gets(option);
//while (hand[1][0] == hand[1][1] )
//{
// hand[1][1] =random(0,51);
//}
//PrintHand(1);
while (1);
}
void main2()
{
int i;
int card1;
int card2;
int card3;
InitDeck();
srand((unsigned int) time(0));
card1 = random(0,51);
card2 = random(0,51);
card3 = random(0,51);
while(card1== card2)
{
card2 = random(0,51);
}
while(card3== card1)
{
card1 = random(0,51);
}
while(card3== card2)
{
card2= random(0,51);
}
PrintCard(card1);
PrintCard(card2);
PrintCard(card3);
GetValue(card1+card2);
printf("= %i\n",GetValue(card1)+GetValue(card2)+GetValue(card3));
for(i=0;i<0;i=i++)
{
printf("deck[%2i] = ",i);
PrintCard(i);
printf("%i",deck[i]);
printf("(%i)\n",GetValue(i));
}
while (1);
}
Day Four:
This was a great last day to the enrichment because it wrapped up the blackjack program and we were all on a good note. Thank You!
Comments (0)
You don't have permission to comment on this page.