1. Player 1 will roll three dice and player 2 will roll two dice. 2. The highest number rolled for each player are compared. If the attacker number is higher, the defender loses one army. If the attacker number is lower than or equal to the defender number, the attacker loses one army. 3. The second highest number rolled for each player are compared. If the attacker number is higher, the defender loses one army. If the attacker number is lower than or equal to the defender number, the attacker loses one army.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Pls, can you help me with this code without using an array?

This is C language btw.

Project 1:
1. Player 1 will roll three dice and player 2 will roll two dice.
2. The highest number rolled for each player are compared. If the attacker number is higher,
the defender loses one army. If the attacker number is lower than or equal to the defender
number, the attacker loses one army.
3. The second highest number rolled for each player are compared. If the attacker number is
higher, the defender loses one army. If the attacker number is lower than or equal to the
defender number, the attacker loses one army.
The third die rolled by the attacker is not used. There are three possible outcomes: The
attacker loses two armies, the defender loses two armies, or each person loses one army
4. Your code must print out:
a. The three numbers rolled by the attacker, in decreasing order (use tabs)
b. The two numbers rolled by the defender, in decreasing order (use tabs)
c. The outcome of the attack.
For example, The attacker roles a 3, 6, 6. The defender roles a 4,6
Sample output for Project 1 would be:
Attacker:
3
Defender
6.
4
Both players lose one army.
Transcribed Image Text:Project 1: 1. Player 1 will roll three dice and player 2 will roll two dice. 2. The highest number rolled for each player are compared. If the attacker number is higher, the defender loses one army. If the attacker number is lower than or equal to the defender number, the attacker loses one army. 3. The second highest number rolled for each player are compared. If the attacker number is higher, the defender loses one army. If the attacker number is lower than or equal to the defender number, the attacker loses one army. The third die rolled by the attacker is not used. There are three possible outcomes: The attacker loses two armies, the defender loses two armies, or each person loses one army 4. Your code must print out: a. The three numbers rolled by the attacker, in decreasing order (use tabs) b. The two numbers rolled by the defender, in decreasing order (use tabs) c. The outcome of the attack. For example, The attacker roles a 3, 6, 6. The defender roles a 4,6 Sample output for Project 1 would be: Attacker: 3 Defender 6. 4 Both players lose one army.
Expert Solution
Step 1

Program Code:

#include<stdio.h>
main()
{
 int a1,a2,a3,d1,d2,highest_a,shighest_a;
 int highest_d,shighest_d,flag_a,flag_d;
 printf("The attacker roles:");
 scanf("%d%d%d",&a1,&a2,&a3);
 printf("\nThe defender roles:");
 scanf("%d%d",&d1,&d2);
 if(a1>a2 && a1>a3)
 {
  highest_a=a1;
  if(a2>a3)
  {
   shighest_a=a2;
  }
  else{
   shighest_a=a3;
  }
 }
 else if(a2>a1 && a2>a3)
 {
  highest_a=a2;
  if(a1>a3)
  {
   shighest_a=a1;
  }
  else{
   shighest_a=a3;
  }
 }
 else
 {
  highest_a=a3;
  if(a1>a2)
  {
   shighest_a=a1;
  }
  else{
   shighest_a=a2;
  }
 }
 if(d1>d2)
 {
  highest_d=d1;
  shighest_d=d2;
 }
 else{
  highest_d=d2;
  shighest_d=d1;
 }
 printf("\nAttacker: %d %d",highest_a,shighest_a);
 printf("\nDefender: %d %d",highest_d,shighest_d);
 if(highest_a>highest_d)
 {
  flag_a=1;
 }
 else{
  flag_a=0;
 }
 if(shighest_a>shighest_d)
 {
  flag_d=1;
 }
 else{
  flag_d=0;
 }
 if(flag_a==1 && flag_d==1)
 {
  printf("\nDefender loses two army");
 }
 else if(flag_a==0 && flag_d==0)
 {
  printf("\nAttacker loses two army");
 }
 else{
  printf("\nBoth players lose one army");
 }
 return 0;
}

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY