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
  • Write an if/else statement that adds 1 to minors if age is less than 18, adds...

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

  • This is Visual Basics... Write an if/else statement that assigns true to the variable fever if...

    This is Visual Basics... Write an if/else statement that assigns true to the variable fever if the variable temperature is greater than 98.6; otherwise it assigns false to fever.* 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.*

  • Use only C++ languages, please!!! Assume: int age; int minors = 0; int adults = 0;...

    Use only C++ languages, please!!! Assume: int age; int minors = 0; int adults = 0; int seniors = 0; 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 inclusive, and adds 1 to the variable seniors if age is 65 or older.

  • Python Write if/else code that adds one to the variable adults if the value of age...

    Python Write if/else code that adds one to the variable adults if the value of age is greater or equal to 18, and adds one to the variable minors otherwise.

  • C++ Write a program that plays the rock, paper, scissors game. Rock beats scissors; scissors beats...

    C++ Write a program that plays the rock, paper, scissors game. Rock beats scissors; scissors beats paper; paper beats rock. You must use these specific functions in your program. These are the prototypes: char generateP2toss(); int checkThrow(char, char); void printStatistics(int, int, int, int); void finalStatistics(int, int, int, int); void welcome(); Notes on these functions: generateP2toss() will generate the computer's toss (the computer is player2). It returns either an "r", "p", or "s/" checkThrow(char char) will check the throw by passing...

  • 1) Write a program that: program starts; declares and initializes to zero an integer variable score;...

    1) Write a program that: program starts; declares and initializes to zero an integer variable score; declares and initializes to zero a float variable total; uses a for loop statement with integer x initialized to 1 going 5 iterations hence x<5 incremented by 0; input from keyboard integer score in range of 0 to 99; print on new line input value; adds score to total; switch x equals 3 break default x++; after exiting the loop calculate the average score;...

  • 1. Write an INSERT statement that adds this row to the Categories table: CategoryName: Brass Code...

    1. Write an INSERT statement that adds this row to the Categories table: CategoryName: Brass Code the INSERT statement so SQL Server automatically generates the value for the CategoryID column. 2. Write an UPDATE statement that modifies the row you just added to the Categories table. This statement should change the Category Name column to “Woodwinds”, and it should use the CategoryID column to identify the row. 3.Write an INSERT statement that adds this row to the Products table: ProductID:...

  • Write a C# program that allows one user to play Rock-Paper-Scissors with computer. The user will...

    Write a C# program that allows one user to play Rock-Paper-Scissors with computer. The user will pick a move (Rock Paper Scissors) from 3 radio buttons and click the play button to play the game. The application will use random number generator to pick a move for the computer. Then, the application display the computer's move and also display whether you won or lost the game, or the game is tie if both moves are the same. The application must...

  • C++ Program 1 – Write a program that determines if a person is an adult. Declare...

    C++ Program 1 – Write a program that determines if a person is an adult. Declare a string variable, firstName. Declare an integer variable, age. Asks the user to enter their first name, and store it in the firstName variable. Asks the user to enter their age in years, and store it in the age variable. If the age is greater or equal to 18, the print out their name and “you are an adult” Else print out their name...

  • For 1 through 11, create an expression using the relational operators, the logical operators, and variable...

    For 1 through 11, create an expression using the relational operators, the logical operators, and variable names of your own choosing, no if or variable declaration is necessary. 1. is a person's age equal to 30? 2. is a body temperature greater than 98.6? 3. is a person's height less than 6 feet? 4. is the current month 12? 5. check if the letter input is m 6. is a person's age equal to 30 and is the person taller...

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