Question

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

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1.solution

#include
int main()
{
   int minors=0,adults=0,seniors=0,n;
   printf("Enter a number\t");
   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\t%d\t%d\t",minors,adults,seniors); // printing the values of variables

2.solution

#include
int main()
{
   int score1,score2,player1Wins=0,player1Losses=0,player2Wins=0,player2Losses=0,tie=0;
   printf("enter score1\t");
   scanf("%d",&score1);
   printf("enter score2\t");
   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");
   }
}

Add a comment
Know the answer?
Add Answer to:
Write in C: 1.) Write an if/else statement that adds 1 to the variable minors if...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT