Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write in C: 1.) Write an if/else statement that adds 1 to the variable minors if

ID: 3756379 • Letter: W

Question

Write in C:

1.) Write an if/else statement that adds 1 to the variable minors if the variable age is less than 18, adds 1 to the variable adults if age is 18 through 64, and adds 1 to the variable seniors if age is 65 or older.

2.) Write a statement that compares the values of score1 and score2 and takes the following actions. When score1 exceeds score2, the message "player1 wins" is printed to standard out. When score2 exceeds score1, the message "player2 wins" is printed to standard out. In each case, the variablesplayer1Wins,, player1Losses, player2Wins, and player2Losses,, are incremented when appropriate.

Finally, in the event of a tie, the message "tie" is printed and the variable tieCount is incremented.

Explanation / Answer

1.solution

#include<stdio.h>
int main()
{
   int minors=0,adults=0,seniors=0,n;
   printf("Enter a number ");
   scanf("%d",&n);
   if(n>=0 && n<18) //age between 0 to 18
   {
       minors=minors+1;
   }
   else if(n>=18 && n<=64) // age from 18 to 64
   {
       adults=adults+1;
   }
   else if(n>=65) // age 65 or above
   {
       seniors=seniors+1;
   }
   else // if negative values enter then this message will be displayed
   {
       printf("enter correct age");
   }
   printf("%d %d %d ",minors,adults,seniors); // printing the values of variables

2.solution

#include<stdio.h>
int main()
{
   int score1,score2,player1Wins=0,player1Losses=0,player2Wins=0,player2Losses=0,tie=0;
   printf("enter score1 ");
   scanf("%d",&score1);
   printf("enter score2 ");
   scanf("%d",&score2);
   if(score1>score2) // player1 score is greater than player2 score
   {
       player1Wins=player1Wins+1;
       player2Losses=player2Losses+1;
      
       printf("player1 wins");
   }
   else if(score2>score1) // player2 score is greater than player1 score
   {
       player2Wins=player2Wins;
       player1Losses=player1Losses;
       printf("player2 wins");
   }
   else if(score1==score2) // both player1 and player2 scores are equal
   {
       tie=tie+1;
       printf("tie");
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote