Question

C++

Write a program that takes in 3 inputs [players (int type), expected game time (double type), team (char type) and calculates actual game time (double) based on the following conditions: if the number of players or the expected game time is less than or equal to ZERO, it should output Wrong input if the number of players is greater than 0 and less than or equal to 6 and if they are on the R or r team, their game time will be 10% faster and if they are on the B or b team, their game time will be 15% faster and if they are on the Y or y team, their game time will be 20% faster and if they are on any other team, they will play 096 faster . If the number of players is greater than 6 but less than or equal to 12 and if they are on the R or and if they are on the B or b team, their game time will be 25% faster and if they are on the Y, or y team their game time will be 30% faster and if they are on any other team, they will play 0% faster team, their game time will be 20% faster ° If the number of players is greater than 12 but less than or equal to 18 . and if they are on the R or r team, their game time will be 30% faster and if they are on the B or b team, their game time will be 35% faster and if they are on the Y or y team, their game time will be 40% faster and if they are on any other team, they will play 096 faster ° If the amount of players is greater than 18, it should output Too many players . Your program should output the total time played in minutes with only two digits following the decimal point. Even though minutes will be fractionalized, you will not have to convert to seconds but will be expected to understand the conversion regardless (ie. 1.50 minutes =-1 minutes and 30 seconds). You have to use both if and else statements to write your code Formula for calculating actual game timeFormula for calculating actual game time: actual_time -expected_time expected_time reduction_percentage/100) Hint: In order to print a double up to only two decimal places, include the library iomanip and use the following syntax cout << fixed; cout << setprecision (2) << actual_time; Input format: When you enter input in input box in zybooks: The first input is amount of players Second input is expected game time in minutes . Third input is the team Output format: It should print the final time based on the amount of players and the team they are on The final time should be printed in minutes up to two decimal places. If the amount of players or the expected game time is less than or equal to O, program should just output Wrong input If the mount of players is greater than 18, then just output Too many players .Sample Input 1: 10 40 r 10 -> stands for amount of players 40 ->stands for expected game time in minutes r-stands for team Sample Output 1: 32.00 minutes Sample Input 2: 0 10 b Sample Output 2: Wrong input Sample Input 3: 19 50 b Sample Output 3: Too many players Sample Input 4: 18 50 e Sample Output 4: 50.00 minutes Sample Input 5: 18 50B Sample Output 5: 32.50 minutes Sample Input 6: 18 50 b Sample Output 6: 32.50 minutes Sample Input 7: 18 -10 b Sample Output 7 Wrong Input

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

#include<iostream>

#include<iomanip>

using namespace std;

int main(){

int players;

double expected_time, actual_time, reduction_percentage;

char team;

cin>>players>>expected_time>>team;

if(players<=0 || expected_time<=0){

cout<<"Wrong input"<<endl;

return 0;

}

else if(players<=6){

if(team=='r' || team=='R')

reduction_percentage = 10;

else if(team=='b' || team=='B')

reduction_percentage = 15;

else if(team=='Y' || team=='Y')

reduction_percentage = 20;

else

reduction_percentage = 0;

}

else if(players<=12){

if(team=='r' || team=='R')

reduction_percentage = 20;

else if(team=='b' || team=='B')

reduction_percentage = 25;

else if(team=='Y' || team=='Y')

reduction_percentage = 30;

else

reduction_percentage = 0;

}

else if(players<=18){

if(team=='r' || team=='R')

reduction_percentage = 30;

else if(team=='b' || team=='B')

reduction_percentage = 35;

else if(team=='Y' || team=='Y')

reduction_percentage = 40;

else

reduction_percentage = 0;

}

else{

cout<<"Too many players"<<endl;

return 0;

}

actual_time = expected_time - ( expected_time * ( reduction_percentage / 100 ));

cout << fixed;

cout << setprecision(2) << actual_time<<" minutes"<<endl;

return 0;

}

Add a comment
Know the answer?
Add Answer to:
C++ Write a program that takes in 3 inputs [players (int type), expected game time (double...
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
  • python program sample output Problem 3 (Taking User Input) Write a function called userGuess(n) that takes...

    python program sample output Problem 3 (Taking User Input) Write a function called userGuess(n) that takes an integer n as an argument. This function should display n to the user and prompt them to enter the number num that is the largest power of 2 less than or equal to n. Have your function return the user's input num (it will be used in the next problem) Problem 4 (Making a Game) Finally, create a main() function for your program....

  • C++ Question 6 (10pt): Convert seconds Write a program that takes a number of seconds as...

    C++ Question 6 (10pt): Convert seconds Write a program that takes a number of seconds as user input (as an integer) and converts it to hours, minutes, and seconds as shown below. You should convert the amount of time in such a way that maximizes the whole numbers of hours and minutes. Expected output 1 (bold is user input) Enter a number of seconds: 60 0 hour(s) 1 minute(s) 0 second(s) Expected output 2 (bold is user input) Enter a...

  • (Statistics) a. Write a C++ program that reads a list of double-precision scores from the keyboard...

    (Statistics) a. Write a C++ program that reads a list of double-precision scores from the keyboard into an array named scores. It is assumed that the user will enter no more than 35 scores. The scores are to be counted as they're read, and entry is to be terminated when a negative value has been entered. After all scores have been input, your program should find and display the sum and average of the scores. The scores should then be...

  • Has to be written in C++. Visual studio. Write a C++ program to realize the game...

    Has to be written in C++. Visual studio. Write a C++ program to realize the game of guessing the number. Generally, the game will generate a random number and the player has to find out the number. In each guess, the program will give you a feedback as your guess is correct, too large, or too small. Then the player play repetitively until find out the number. Specifically, the game plays as the following. a). When the game is started,...

  • Python Program Python: Number Guessing Game Write a Python function called "Guess.py" to create a number...

    Python Program Python: Number Guessing Game Write a Python function called "Guess.py" to create a number guessing game: 1. Function has one input for the number to Guess and one output of the number of attempts needed to guess the value (assume input number will always be between 1 and 1000). 2. If no number was given when the function was called, use random.randint(a,b) to generate a random number between a=1 and b=1000. You will also need to add an...

  • Use C programming Make sure everything works well only upload Write a program that takes an...

    Use C programming Make sure everything works well only upload Write a program that takes an integer from standard input and prints all prime numbers that are smaller than it to standard output. Recall that a prime number is a natural number greater than 1 whose only positive divisors are 1 and itself. At the start of the program, prompt the user to input a number by printing "Input a number greater than 2:\n". If the user's input is less...

  • For a C program hangman game: Create the function int play_game [play_game ( Game *g )]...

    For a C program hangman game: Create the function int play_game [play_game ( Game *g )] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) (Also the link to program files (hangman.h and library file) is below the existing code section. You can use that to check if the code works) What int play_game needs to do mostly involves calling other functions you've already...

  • PLEASE WRITE CODE FOR C++ ! Time Validation, Leap Year and Money Growth PartA: Validate Day and Time Write a program tha...

    PLEASE WRITE CODE FOR C++ ! Time Validation, Leap Year and Money Growth PartA: Validate Day and Time Write a program that reads a values for hour and minute from the input test file timeData.txt . The data read for valid hour and valid minute entries. Assume you are working with a 24 hour time format. Your program should use functions called validateHour and validateMinutes. Below is a sample of the format to use for your output file  timeValidation.txt :   ...

  • C or C++ Project Overview Wild, Wild, West! Dice Game The Wild, Wild, West! is an...

    C or C++ Project Overview Wild, Wild, West! Dice Game The Wild, Wild, West! is an elimination dice game. It can be played by any number of players, but it is ideal to have three or more players. Wild, Wild, West! Requires the use of two dice. At the start of the game, each player receives a paper that will track the number of lives that player has. Each player starts the game with 6 lives. In the first round,...

  • You will write a two-class Java program that implements the Game of 21. This is a...

    You will write a two-class Java program that implements the Game of 21. This is a fairly simple game where a player plays against a “dealer”. The player will receive two and optionally three numbers. Each number is randomly generated in the range 1 to 11 inclusive (in notation: [1,11]). The player’s score is the sum of these numbers. The dealer will receive two random numbers, also in [1,11]. The player wins if its score is greater than the dealer’s...

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