Fill In Your Own Header Comment

Fill In Your Own Header Commentincludeincludeincludeinclude C

Fill in your own header comment

// Constants to be used. // Passing score

define SCORE 70

define FALSE 0

define TRUE 1

// Function prototypes - do not change these

void set_stats(int d_strength, int d_intel, int * d_agil);

void print_stats(int strength, int intelligence, int agility, char name[]);

int menu();

int weather();

int train_strength(int weather, char name[]);

int train_intelligence(int weather, char name[]);

int train_agility(int weather, char name[]);

int obstacle_course(int weather, int strength, int intel, int agility);

void end_message(int completed, char name[]);

// Main function

int main() {

int num_day, ans, weather_value, score = 0, completed = FALSE;

int dragon_strength, dragon_intelligence, dragon_agility;

char name[20], answer[4];

srand(time(0));

printf("Welcome to Dragon Training!\n");

printf("You've been assigned a new dragon!\nWould you like to give it a name? (yes/no)\n");

scanf("%s", answer);

if(strcmp(answer, "yes") == 0) {

printf("Great! What would like to call your dragon?\n");

scanf("%s", name);

} else strcpy(name, "your dragon");

printf("\nTo complete training, %s must finish the final \nobstacle course with a score of 70 or better.\n", name);

printf("\nYou may attempt the obstacle course at any time, \nbut you must finish within 10 days.\n");

printf("\nBetter get started!\n");

set_stats(&dragon_strength, &dragon_intelligence, &dragon_agility);

for (num_day = 1; num_day

printf("\nIt is Day #%d.\n", num_day);

print_stats(dragon_strength, dragon_intelligence, dragon_agility, name);

weather_value = weather();

ans = menu();

switch(ans) {

case 1: dragon_strength += train_strength(weather_value, name); break;

case 2: dragon_intelligence += train_intelligence(weather_value, name); break;

case 3: dragon_agility += train_agility(weather_value, name); break;

case 4: score = obstacle_course(weather_value, dragon_strength, dragon_intelligence, dragon_agility);

printf("%s scored a %d on their obstacle course run!\n", name, score);

break;

}

if(score >= SCORE) {

completed = TRUE;

break;

}

}

end_message(completed, name);

return 0;

}

// Pre-conditions: d_strength, d_intel, and d_agil are pointers to variables that store

// the dragon's strength, intelligence, and agility statistics.

// Post-condition: Each of the dragon's statistics are set to a pseudorandom

// initial value. Strength should be a random value from 0-99, then add 5.

// Intellect should be a random value from 1-10.

// Agility should be a random value from 0-19, then add 2.

void set_stats(int d_strength, int d_intel, int * d_agil) {

*d_strength = rand() % 100 + 5;

*d_intel = rand() % 10 + 1;

*d_agil = rand() % 20 + 2;

}

// Pre-conditions: There are no parameters for this function.

// Post-condition: The user is presented with a menu and given

// the opportunity to respond. If they respond with

// a valid menu option, return the user's choice.

// What to do in this function: Prompt the user with the menu and

// read in their response. If their answer is less than 0 or greater

// than 4, continue to prompt them until they provide a valid answer.

// Then, return their answer.

int menu() {

int choice;

do {

printf("\nMenu:\n");

printf("1. Train Strength\n");

printf("2. Train Intelligence\n");

printf("3. Train Agility\n");

printf("4. Attempt Obstacle Course\n");

printf("Enter your choice (1-4): ");

scanf("%d", &choice);

} while (choice 4);

return choice;

}

// Author: Arup Guha

// Pre-condition: None

// Post-condition: The weather report for the day is printed and the

// corresponding weather status in between 1 and 5,

// inclusive, is returned.

int weather() {

int retval = rand() % 5 + 1;

printf("\nHere is today's weather forecast:\n");

if (retval == 1) printf("It is cloudy with a high chance of rain.\n");

else if (retval == 2) printf("It is partly cloudy and windy.\n");

else if (retval == 3) printf("It is partly sunny with low humidity.\n");

else if (retval == 4) printf("It is warm and sunny with medium winds.\n");

else printf("It's a perfect beach day. Sunny and hot!\n");

printf("\n");

return retval;

}

// Pre-condition: strength, intelligence, agility, and name are variables

// that represent the name of the dragon and its stats

// Post-condition: A listing of the dragon's stats are printed

// What to do with this function: Print the stats in a formatted manner

void print_stats(int strength, int intelligence, int agility, char name[]) {

printf("Dragon '%s' Stats:\n", name);

printf("Strength: %d\n", strength);

printf("Intelligence: %d\n", intelligence);

printf("Agility: %d\n", agility);

}

// Pre-condition: weather is an integer from 1-5 that represents the

// current day's forecast. name is the dragon's name.

// Post-condition: A day's strength training is carried out.

// The current gain in strength is printed and returned.

// What to do with this function: Determine max gain, generate random gain, print and return

int train_strength(int weather, char name[]) {

int max_gain = weather * 3 + 5;

if (max_gain

int gain = rand() % max_gain + 1;

printf("%s's strength increased by %d!\n", name, gain);

return gain;

}

// Pre-condition: weather is an integer from 1-5 that represents the

// current day's forecast. name is the dragon's name.

// Post-condition: A day's knowledge training is carried out.

// The current gain in knowledge is printed and returned.

// Determine max gain, generate random gain, print and return

int train_intelligence(int weather, char name[]) {

int max_gain = 15 / weather + 5;

if (max_gain

int gain = rand() % max_gain + 1;

printf("%s's intelligence increased by %d!\n", name, gain);

return gain;

}

// Pre-condition: weather is an integer from 1-5 that represents the

// current day's forecast. name is the dragon's name.

// Post-condition: A day's agility training is carried out.

// The current gain in agility is printed and returned.

// Determine max gain, generate random gain, print and return

int train_agility(int weather, char name[]) {

int max_gain = 13 + weather % 5 + (weather + 4) % 5;

int gain = rand() % max_gain + 1;

printf("%s's agility increased by %d!\n", name, gain);

return gain;

}

// Pre-condition: weather is an integer from 1-5 that represents the

// current day's forecast. strength, intel, and agility

// are variables representing the dragon's stats.

// Post-condition: A day's obstacle course is run and a score for the

// run is returned.

int obstacle_course(int weather, int strength, int intel, int agility){

return 10 + 2 * weather + strength / 4 + intel + agility / 2;

}

// Pre-condition: completed is an integer that represents either TRUE or FALSE

// name is the dragon's name.

// Post-condition: The user's overall result is printed out.

// What to do with this function: Print success or failure message.

void end_message(int completed, char name[]) {

if (completed) {

printf("Congratulations! %s has successfully mastered the obstacle course!\n", name);

} else {

printf("Training incomplete. %s did not finish the obstacle course within the time limit.\n", name);

}

}