i need to do this and am unsure how to generate the computers output the question is as follows:
Add code to generate the computer's choice.
Use the rand() function to simulate the computer’s choice (i.e. 1 + (rand() % 2) where 1 represents the
computer choosing steal and 2 represents the computer choosing deal). Display the computer's choice to the screen
as seen below.
Sample output 1:
Jackpot: 100
Steal, Deal or Quit [s|d|q]? s
You chose: Steal
Comp chose: Steal
Sample output 2:
Jackpot: 100
Steal, Deal or Quit [s|d|q]? s
You chose: Steal
Comp chose: Deal
Sample output 3:
Jackpot: 100
Steal, Deal or Quit [s|d|q]? d
You chose: Deal
Comp chose: Steal
Sample output 4:
Jackpot: 100
Steal, Deal or Quit [s|d|q]? d
You chose: Deal
Comp chose: Deal
My code currently is listed below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
#include<stdio.h>
int main()
{
char steal;
steal = 's';
char deal;
deal = 'd';
char quit;
quit = 'q';
printf("\n\nProgramming Assignment\n\n");
/*Choosing Steal*/
printf("\nJackpot: 100\n");
printf("Steal, Deal or Quit [s|d|q]?");
scanf_s(" %c", &steal);
printf("\n\nyou chose: steal\n\n");
/*Choosing Deal*/
printf("\nJackpot: 100\n");
printf("Steal, Deal or Quit [s|d|q]?");
scanf_s(" %c", &deal);
printf("\n\nyou chose: deal\n\n");
return 0;
}
|