|
Blackjack Program in C
#include <stdio.h> needed
to get access to C's standard input output library
#include <stdlib.h>
int main() start
of execution of program
{
int total; initialize
the integer total
int counter; initialize
the integer counter
int myArray[13]; initialize
an array with 13 elements
counter = 0; declare
counter starts at 1
total = 0; declare total
starts at 1
do The condition
{
myArray[counter]=rand() % 13; create
a random number up to 13
printf("%i\n", myArray[counter]);
print out the random number to check
total = total + myArray[counter++]; running
total (add one)
}
while (total<21);
if total
printf("bust");
printf("total = %i\n",
total);
return 0;
}
#include <stdio.h>
main()
{
int target;
int guess;
int again;
printf("\n Do you want to
guess a number 1 =Yes, 0=No ");
scanf("%d",&again);
while (again)
{
target = rand() % 100;
printf('\n What is your guess
? ");
scanf("%d",&guess);
while(target!=guess)
{
if (target>guess) printf("Too low");
else printf("Too high");
printf('\n What is your guess ? ");
scanf("%d",&guess);
}
printf("\n Well done you
got it! \n");
printf("\n Do you want to guess a number
1=Yes, 0=No");
scanf("%d".&again);
}
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
int total;
int counter;
int hearts[13];
counter = 0;
total = 0;
do
{
hearts[counter]=rand() % 14;
printf("%i\n", hearts[counter]);
total = total + hearts[counter++]; add
one to counter
}
if (total>22);
printf("total = %i\n", total);
return 0;
}
#include <stdio.h>
int main()
{
int hearts[13]
hearts[0]=0;
hearts[1]=0;
hearts[2]=0;
hearts[3]=0;
hearts[4]=0;
hearts[5]=0;
hearts[6]=0;
hearts[7]=0;
hearts[8]=0;
hearts[9]=0;
hearts[10]=0;
hearts[11]=0;
hearts[12]=0;
#include <stdio.h>
int main() {
int hearts[13] = {0,0,0,0,0,0,0,0,0,0,0,0,0};
int diamonds[13] = {0,0,0,0,0,0,0,0,0,0,0,0,0};
int spades[13] = {0,0,0,0,0,0,0,0,0,0,0,0,0};
int clubs[13] = {0,0,0,0,0,0,0,0,0,0,0,0,0};
int i;
int counter;
int dealerTotal;
for(i=0 ; i<13 ; i++) {
printf("hearts[%d] has a value of %d\n",
i, hearts[i]);
}
for(dealerTotal=0; dealerTotal<21; dealerTotal++)
{hearts[13]=rand() % 14;
dealerTotal= hearts + dealerTotal;
printf("%i", dealerTotal);
}
return 0;
}
#include <stdio.h>
int main() {
int hearts[13] = {0,0,0,0,0,0,0,0,0,0,0,0,0};
int diamonds[13] = {0,0,0,0,0,0,0,0,0,0,0,0,0};
int spades[13] = {0,0,0,0,0,0,0,0,0,0,0,0,0};
int clubs[13] = {0,0,0,0,0,0,0,0,0,0,0,0,0};
int i;
int counter;
int dealerTotal;
int suite; initialize
the integer numbers
suite = rand() % 4;
printf("suite = %i\n", suite);
if (suite==1) hearts[rand() % 13]=1;
if (suite==2) spades[rand() % 13]=1;
if (suite==3) diamonds[rand() % 13]=1;
if (suite==4) clubs[rand() % 13]=1;
printf ("%i\n", hearts[0]);
printf ("%i\n", hearts[1]);
printf ("%i\n", spades[1]);
return 0;end
program return no error code
}
|