Question

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 robots 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 robots 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.

help me with the loops and the last part of this question .i am using c language....speed=distance/time....in the 1st part of the program i had to write a program to calculate speed...we had to input distance in meters and time in seconds.

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

please find the output screenshot and code below.

code :

//defining the predefined libraries

#include<stdio.h>

#include <time.h>

#include <stdlib.h>

//defining the method for calculating the speed

//here the distance is the parameter

float calculate_speed(float finish_line_distance) {

int time;

//time taking as the input from the user

printf("Enter the time in seconds : \n");

scanf("%d",&time);

//calculating speed = distance/time

float res = (finish_line_distance/time);

//returning the speed

return res;

}

//method for calculating the strength

int calculate_strength() {

int number;

//asking the user to enter the number between 0 and 100

printf("Enter a whole number between 0 and 100\n");

//reading a number from the console

scanf("%d",&number);

//returning the number

return number;

}

//calculating the combat value

int calculate_combat(float speed, int strength){

int minValue = 50;

//calculating the min(50,speed)

if(speed < 50) {

minValue = speed;

}

//generating the random value between -10 and 10

srand(time(NULL));

int nRandonNumber = (rand()%((10+1)-(-10)) + (-10));

printf("random number is %d\n",nRandonNumber);

//calculating the combat using the formaula given

float res = (minValue + ((strength/100) * 50) + nRandonNumber);

//returning the combat

return res;

}

//our main method starts here

void main() {

//defining the variables

float finish_line_distance,speed;

int strength;

//reading the distance from the user

printf("Enter the finish Line Distance : \n");

scanf("%f",&finish_line_distance);

//calling the function speed to calculate speed

float res = calculate_speed(finish_line_distance);

printf("speed is %f\n",res);

//calling the strength function to calculate strength

int res1 = calculate_strength();

printf("the strength is %d\n",res1);

//calling the combat function to calcualte the combat

int res2 = calculate_combat(res,res1);

//printing the result

printf("the comabat values is %d\n",res2);

}

output screenshot :

Add a comment
Know the answer?
Add Answer to:
help me with the loops and the last part of this question .i am using c...
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
  • I am struggling with a program in C++. it involves using a struct and a class...

    I am struggling with a program in C++. it involves using a struct and a class to create meal arrays from a user. I've written my main okay. but the functions in the class are giving me issues with constructors deconstructors. Instructions A restaurant in the Milky way galaxy called “Green Alien” has several meals available on their electronic menu. For each food item in each meal, the menu lists the calories per gram and the number of grams per...

  • Summary task: C++ language; practice combining tools(functions, arrays, different kind of loops) to solve somewhat complex...

    Summary task: C++ language; practice combining tools(functions, arrays, different kind of loops) to solve somewhat complex problem. Description A Valiant Hero is about to go on a quest to defeat a Vile Monster. However, the Hero is also quite clever and wants to be prepared for the battle ahead. For this question, you will write a program that will simulate the results of the upcoming battle so as to help the hero make the proper preparations. Part 1 First, you...

  • Please I need help in C language, I am trying to modify the code per the...

    Please I need help in C language, I am trying to modify the code per the below instructions, but I am getting errors. Can't fgure it out. The attempted code modification and data file is privided below, after the instructions. Thank you. Instructions:                  1.      First, add a function named printMsg that displays a message, a greeting, or an introduction to the program for the user. Add a statement that calls that function from the main function when your program starts....

  • c++, I am having trouble getting my program to compile, any help would be appreciated. #include...

    c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...

  • In C++, Please help me compute the following flowchart exactly like this requirement: Use while loops...

    In C++, Please help me compute the following flowchart exactly like this requirement: Use while loops for the input validations required: number of employees(cannot be less than 1) and number of days any employee missed(cannot be a negative number, 0 is valid.) Each function needs a separate flowchart. The function charts are not connected to main with flowlines. main will have the usual start and end symbols. The other three functions should indicate the parameters, if any, in start; and...

  • Please, I need help, I cannot figure out how to scan variables in to the function...

    Please, I need help, I cannot figure out how to scan variables in to the function prototypes! ******This is what the program should look like as it runs but I cannot figure out how to successfully build the code to do such.****** My code: #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <math.h> #include <conio.h> float computeSeriesResistance(float R1, float R2, float R3); float computeParallelResistance(float R1, float R2, float R3); float computeVoltage(int current, float resistance); void getInputR(float R1, float R2, float R3); void getInputCandR(int...

  • In c++ programming, can you please edit this program to meet these requirements: The program that...

    In c++ programming, can you please edit this program to meet these requirements: The program that needs editing: #include <iostream> #include <fstream> #include <iomanip> using namespace std; int cal_avg(char* filenumbers, int n){ int a = 0; int number[100]; ifstream filein(filenumbers); if (!filein) { cout << "Please enter a a correct file to read in the numbers from"; }    while (!filein.eof()) { filein >> number[a]; a++; } int total = number[0]; for (a = 0; a < n; a++) {...

  • Code in C++ Function Prototypes For the second part of the lab activity, you will be...

    Code in C++ Function Prototypes For the second part of the lab activity, you will be practicing writing function prototypes. Continue working on the same project from part A. First, rewrite the code so that you are using function prototypes for the functions getNumber.getMessage, and repeat. Remember that the prototypes go at the top of the file, followed by main, then the definitions of the three functions at the end. Second, you will be creating a new function (procedure) called...

  • I need help with this C++ problem so far my algorithm is looking like this. #include...

    I need help with this C++ problem so far my algorithm is looking like this. #include using namespace std; void input(char fullname[35], int weight, int distance); double totalcharges(); main() { char fullname[35]; int weight; int distance; for(int i = 1; i <= 3; i++) {   input(fullname, weight, distance); } } void input(char fullname[35], int weight, int distance) { char f[35]; //full name int w; // weight int d; // distance cout << "What is your full name? Please enter `...

  • (C++) Hey guys we just went over loops and it got me confused, it has me...

    (C++) Hey guys we just went over loops and it got me confused, it has me scrathcing my head for the past two days. I would appreciate any help you guys have to offer. Few places I have a hard time is get input and determine winner(cummulative part). Write a program that lets the user play the Rock, Paper, Scissors game against the computer. The computer first chooses randomly between rock, paper and scissors, but does not display its choice....

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