how to create the functions?..plz hepl 2. Strength. The robots will attempt to l
ID: 3748386 • Letter: H
Question
how to create the functions?..plz hepl
2. Strength. The robots will attempt to lift several heavy objects 3. Combat effectiveness. The robots will battle against 100 humans and then receive a score based on the number of victories. Create three functions (one for each phase). 1. float calculate_speed (float finish_line_distance) 2. int calculate_strength() 3. int calculate_combat(float speed, int strength) calculate_speed() should take the distance to the finish line as an argument, perform the speed test from the first workshop and return the robot's speed. calculate_strength () should prompt the user to input a whole number between O and 100 (representing the number of objects the robot could successfully lift) and return that number. calculate_combat() should simulate 100 rounds of combat against human opponents. A robot's percentage chances of winning in combat can be calculated using the following formula: strength Min speed, 50) + 100 X 50 The "Min" portion of the formula can be read as "either speed or 50, whichever is smallest" The +10 portion of the formula should be calculated as a random number from -10 to 10 The function should use random number generation for the combat and return a whole number representing the total number of victories. The program should also include a main() function that calls each of the above three functions in sequence At the end of the main function, the user should be asked if they would like to repeat the simulation again. The program should not end under any circumstances other than the user choosing not to repeat.Explanation / Answer
1. To create float calculate_speed(foat finish_line_distance) function:
You have to perform speed test using the program which you have created earlier for calculating speed and then return speed.
2. To create int calculate_strength() function:
Just input from the user an integer between 0 to 100 and return the integer. Like this:
int s;
cin>>s; //Input strength from user
return s; //Return stength
3. To create int calculate_combat(float speed, int strength) function:
First of all find which one is minimum, speed or 50. Then store the minimum in a variable let's say min. To find minimum of speed and 50:
if(speed < 50)
min = speed;
else
min = 50;
then use a vaiable to store any random number between -10 to 10. Let's say that variable is r.
Then do like this:
srand(time(NULL)); //To provide seed for rand() function. Use cstdlib and time.h for this to work
r = -10 + rand() % 20; //Generate random number between -10 and 10 and store it in r
Then finally return percent chances of winning by performing calculation like this:
return ( min + (strength * 50 / 100) + r; // Return the percentage
4. To create main() function:
Just call above three functions inside a do-while loop and add after calling above functions ask the user if they would like to repeat the simulation again. If yes then repeat the process else exit. Like this inside main:
char c;
do
{
speed = calculate_speed(finish_line_distance);
strength = calculate_strength();
combat = calculate_combat(speed, strength);
//...do something here...
cout<<"Repeat simulation?(Y/N) : ";
cin>>c;
}while(c == 'Y' || c == 'y'); //Make this loop work till c is either 'y' or 'Y'
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.