Question

This is a multipart question, needs to be in c language, and be able to compile...

This is a multipart question, needs to be in c language, and be able to compile into a windows program, i.e. code blocks, specifically.

In C language:

You are to design a fight game between Neo versus Smith. The program needs to be organized using at least three functions. The specifications are as follows:

  1. The program should first call a password function.
    1. Request a password, multiple characters followed by return.
    2. For every character entered, display * character.
    3. The correct password is EGC251.
    4. If the correct password is entered, proceed to the game.
    5. If a wrong password is entered, prompt the user with a statement indicating the password is incorrect and prompt the user for a correct password. If the second password is also incorrect, prompt the user that this is the last attempt. If the third password is entered incorrectly, ignore further attempts.
  1. The game consists of three rounds. At each level, a new health-level is calculated. At the end of the third round, the one with the higher health level is announced the winner.
  2. Initially, value of health-level is randomized between 20.0 and 24.99.
  3. During each round, two sequential integer inputs punch_N and punch_S between 2 and 5 are accepted.
  4. Following each punch, the damage (in float) to the opponent is calculated using

damage_S = punch_N * (health_level_S*randomized(0.05 - .1)

damage_N = punch_S * (health_level_N*randomized(0.05 - .1)

  1. Using individual damage, a new health level is calculated using

health_S = health_S * skill– damaged_S

health_N = health_N * skill – damaged_N

Note that skill is a float variable which needs to be randomized between 0.9 and 1.1 each time it is used.   

  1. If the health level of a fighter drops below 0.5, the fight is over by a knock out.
  2. Otherwise, proceed to the next round.
  3. After three rounds using the health_level of fighters, determine the winner.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//********************************************START OF PROGRAM***************************************************

#include <stdio.h>
#include <string.h> // for using strcmp()
#include <conio.h> //for using getch()
#include <stdlib.h> // for using rand() and srand()
#include <time.h> // for using time() function

float punch_N, punch_S, health_level_N, health_level_S, damage_S, damage_N, skill;
int gameflag = 0, rounds = 0;


int passIsCorrect(char *password){ //checks the correctness of password
if(strcmp(password, "EGC251") == 0) return 1; //return 1 for correct password
else return 0;
}

float randomize(float upper, float lower){
// to generate a random number between a range
// the formula num = (rand() % (upper - lower + 1)) + lower is used

int up = upper * 1000;
int low = lower * 1000;
return ((rand() % (up - low + 1)) + low) / 1000.0;

//in order to generate random number between two floating point numbers
//we first multiply the two numbers by 1000 and find random number
//between them. Dividing this generated number by 1000 gives us the
//desired random number between two floating numbers
}
void setHealth(){ // sets health of neo and smith before game begins

health_level_N = randomize(24.99, 20.00);
health_level_S = randomize(24.99, 20.00);

}

void calculateDamage(){ // calculates the damage dealt according to given formula

damage_S = punch_N * (health_level_S*randomize(0.05, 0.10));
damage_N = punch_S * (health_level_N*randomize(0.05, 0.1));


}

void calculateHealth(){ //calculates health after damages are dealt

skill = randomize(0.90, 1.10);
health_level_S = health_level_S * skill - damage_S;

skill = randomize(0.90, 1.10);
health_level_N = health_level_N * skill - damage_N;
}

void displayStats(){
printf("\n\n\tROUND %d: ", rounds);
printf("\n\n\t\t Neo's Health = %.2f", health_level_N);
printf("\n\n\t\t Smith's Health = %.2f", health_level_S);
}

void decideWinnerByKnockOut(){ //checks is any player is knocked out
if(health_level_N < 0.5){
printf("\n\nSMITH WINS BY KNOCKING NEO OUT!");
gameflag = 0;
}
else if(health_level_S < 0.5){
printf("\n\nNEO WINS BY KNOCKING SMITH OUT!");
gameflag = 0;
}

}

void decideWinner(){ //decides winner after completion of rounds
if(health_level_N < health_level_S){
printf("\n\nSMITH WINS!");
}
else if(health_level_S < health_level_N){
printf("\n\nNEO WINS!");
}

}

void main(){
srand(time(0)); //to generate a different random value every time

char password[15], ch;
int i, passAttempt = 0;

do{ //loop to input and check password
i = 0;
printf("\nEnter 6 digit password(press enter to submit): ");
ch = getch();
while(ch != 13){
password[i++] = ch;
ch = '*';
printf("%c", ch);
ch = getch();
}
password[i] = '\0';
if(passIsCorrect(password)){
gameflag = 1;
break;
}
else{
passAttempt++;
printf("\nPassword is incorrect.");

}
}while(passAttempt < 3);
if(gameflag){
setHealth();
fflush(stdin);
while(rounds < 3 && gameflag){
rounds++;
printf("\nEnter punch value between 2 and 5: ");
scanf("%f%f", &punch_N, &punch_S);
calculateDamage();
calculateHealth();
displayStats();
decideWinnerByKnockOut();
}
decideWinner();
}
}

//***************************************************END OF PROGRAM*******************************************************

Note:

After you copy-paste this code into any code editor(example code blocks) if you face an error "stray character '\266' ", please remove all minus signs '-' and rewrite them using your own keyboard minus sign '-'. This is a common error often faced by programmers when they copy paste code from the internet. The text editor does not recognize the hyphens from the copied code.

Add a comment
Know the answer?
Add Answer to:
This is a multipart question, needs to be in c language, and be able to compile...
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
  • This is a multipart question In C language: You are to design a fight game between...

    This is a multipart question In C language: You are to design a fight game between Neo versus Smith. The program needs to be organized using at least three functions. The specifications are as follows: The program should first call a password function. Request a password, multiple characters followed by return. For every character entered, display * character. The correct password is EGC251. If the correct password is entered, proceed to the game. If a wrong password is entered, prompt...

  • PLEASE INCLUDE SAW-PROMPTS FOR 2 PLAYERS NAMES(VALIDATE NAMES). SHOW MENU (PLAYER MUST SELECT FROM MENU B4...

    PLEASE INCLUDE SAW-PROMPTS FOR 2 PLAYERS NAMES(VALIDATE NAMES). SHOW MENU (PLAYER MUST SELECT FROM MENU B4 THE GAME STARTS 1=PLAY GAME, 2=SHOW GAME RULES, 3=SHOW PLAYER STATISTICS, AND 4=EXIT GAME WITH A GOODBYE MESSAGE.) PLAYERS NEED OPTION TO SHOW STATS(IN A DIFFERNT WINDOW-FOR OPTION 3)-GAME SHOULD BE rock, paper, scissor and SAW!! PLEASE USE A JAVA GRAPHICAL USER INTERFACE. MUST HAVE ROCK, PAPER, SCISSORS, AND SAW PLEASE This project requires students to create a design for a “Rock, Paper, Scissors,...

  • help me with the loops and the last part of this question .i am using c...

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

  • In C language using printf and scanf statements: Write a program to display a histogram based...

    In C language using printf and scanf statements: Write a program to display a histogram based on a number entered by the user. A histogram is a graphical representation of a number (in our case, using the asterisk character). On the same line after displaying the histogram, display the number. The entire program will repeat until the user enters zero or a negative number. Before the program ends, display "Bye...". The program will ask the user to enter a non-zero...

  • This program is part 1 of a larger program. Eventually, it will be a complete Flashcard...

    This program is part 1 of a larger program. Eventually, it will be a complete Flashcard game. For this part, the program will Prompt the user for a file that contains the questions – use getline(cin, fname) instead of cin >> fname to read the file name from the user. This will keep you in sync with the user’s input for later in the program The first line is the number of questions (just throw this line away this week)...

  • (C Programming language, not C++ and MUST Compile) Companies and people often buy and sell stocks....

    (C Programming language, not C++ and MUST Compile) Companies and people often buy and sell stocks. Often they buy the same stock for different prices at different times. Say one owns 1000 shares a certain stock (such as Checkpoint), one may have bought the stock in amounts of 100 shares over 10 different times with 10 different prices. We will analyze two different methods of accounting, FIFO and LIFO accounting used for determining the “cost” of a stock. This is...

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

  • c language This assignment is to write a program to score the paper-rock-scissors game AGAIN. Each...

    c language This assignment is to write a program to score the paper-rock-scissors game AGAIN. Each of two players enters either P, R, or S. The program then announces the winner as well as the basis for determining the winner: “Paper covers rock”, “Rock breaks scissors”, “Scissors cut paper”, or “Draw, nobody wins”. The primary differences between this and previous two versions are described as below: (1) You MUST use a function to get the input value for the player’s...

  • Step 3: How would you write this script in C? It needs to do the things...

    Step 3: How would you write this script in C? It needs to do the things required in step 3. 1. You have received a new batch of distinguished users; their basic information is located in newusers.tar. Inside of the tar file, there is a file called "newusers.txt" which contains a colon-separated entry for each user: the username, the uid, the GECOS information, and the user's preferred shell. Also in the tar file you will find a public key for...

  • In the language c using the isspace() function: Write a program to count the number of...

    In the language c using the isspace() function: Write a program to count the number of words, lines, and characters in its input. A word is any sequence of non-white-space characters. Have your program continue until end-of-file. Make sure that your program works for the case of several white space characters in a row. The character count should also include white space characters. Run your program using the following three sets of input:             1. You're traveling through ​               another...

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