Creating A Simulated Output

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;
}
Maybe like this:
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
#include <stdio.h>
#include <stdlib.h> 
#include <time.h>

#define DEAL  1
#define STEAL 2

int main()
{
  char deal = NULL;
  int computer_choice = 0;

  srand((unsigned)time(NULL));
  printf("\n\nProgramming Assignment\n\n");

  printf("Steal, Deal or Quit [s|d|q]?");
  scanf_s(" %c", &deal, sizeof(deal));
  if (deal == 's' || deal == 'S')
    printf("\n\nyou chose: Steal\n\n");
  else if (deal == 'd' || deal == 'D')
    printf("\n\nyou chose: Deal\n\n");
  else if (deal == 'q' || deal == 'Q')
    return 0;
  else
    printf("\n\nWRONG CHOICE");

  computer_choice = 1 + (rand() % 2);

  if (computer_choice == DEAL)
  {
    /* Your output here*/
  }
  else if (computer_choice == STEAL)
  {
    /* Your output here*/
  }

  return 0;
}
Topic archived. No new replies allowed.