Question: Hi there I'm having trouble with this C coding project that deals with functions, this is my first time dealing with them, thank you so

Hi there I'm having trouble with this C coding project that deals with functions, this is my first time dealing with them, thank you so much in advance !

This is the code I've done so far -

//Included Libraries

#include #include #include

//Constants for Arrays #define STRLENGTH 30 #define NUMCREW 5 #define NUMSUPPLIES 4

//Constants for Distances (measured in miles) #define CANARY 1261 #define GRENADA 3110 #define FINAL 500 #define DISTANCE 4871

//Function Signatures - do not change these void setup(char crewnames[NUMCREW][STRLENGTH], int crewstatus[NUMCREW], int supplies[NUMSUPPLIES], int *captaintype, int *funds, int *distanceperday); int countcrew(int crewstatus[NUMCREW]); void printstatus(char crewnames[NUMCREW][STRLENGTH], int crewstatus[NUMCREW]); void getsupplies(char supplytypes[NUMSUPPLIES][STRLENGTH], int supplies[NUMSUPPLIES], int *funds); void dailyreport(char crewnames[NUMCREW][STRLENGTH], int crewstatus[NUMCREW], int supplies[NUMSUPPLIES], int funds, int traveled); void rest(int supplies[NUMSUPPLIES], char crewnames[NUMCREW][STRLENGTH], int crewstatus[NUMCREW], int *days); int fish(); int max(int a, int b); int min(int a, int b); void event(char crewnames[NUMCREW][STRLENGTH], int crewstatus[NUMCREW], int *days, int supplies[NUMSUPPLIES]);

//Main function - This is the final version of main. Any changes you make while //creating the functions should be removed prior to submission. int main(void) { //crewnames and supplytypes are arrays of strings to store the names of the crew members //and the types of supplies that can be purchased and taken on the voyage char crewnames[NUMCREW][STRLENGTH]; char supplytypes[NUMSUPPLIES][STRLENGTH] = {"Food", "Clothes", "Ship Parts", "Shovels"}; //stop indicates whether or not the user would like to stop at a port //crewstatus indicates the status of each crew member, corresponding to the order of names //supplies has a total for each type of supply, corresponding to the order of supplies char stop; int crewstatus[NUMCREW], supplies[NUMSUPPLIES]; //the distanceperday and funds depends on the captaintype the user selects //day is the current day, traveled is the total miles traveled, i is a loop counter //and action stores the intended action of the user for the day int distanceperday, captaintype, funds, traveled=0, day=1; int i, action;

//seed the pseudorandom number generator srand(time(0));

//initialize each variable with information from the user setup(crewnames, crewstatus, supplies, &captaintype, &funds, &distanceperday);

//begin the game by purchasing initial supplies printf(" Before leaving Port Marin, you should purchase some supplies. "); getsupplies(supplytypes, supplies, &funds);

//continue the voyage until the ship reaches the intended destination //if all crew members perish, the journey cannot continui while (traveled < DISTANCE && countcrew(crewstatus) > 0) { printf(" --It is day #%d.-- ", day);

//check to see if the ship has reached the next port if(traveled >= (GRENADA+CANARY) && traveled < (GRENADA + CANARY + distanceperday) ) { printf("You have arrived at Grenada, at the edge of the Carribbean Sea. "); printf("Would you like to make port? (Y/N) "); scanf(" %c", &stop);

if (stop == 'Y' || stop == 'y') getsupplies(supplytypes, supplies, &funds);

traveled = (GRENADA+CANARY) + distanceperday; } else if (traveled >= CANARY && traveled < (CANARY + distanceperday) ) { printf("You have arrived at the Canary Islands. "); printf("Would you like to make port? (Y/N) "); scanf(" %c", &stop);

if (stop == 'Y' || stop == 'y') getsupplies(supplytypes, supplies, &funds);

traveled = CANARY + distanceperday; } //if between destinations: print the daily report and process the user's action for the day else { dailyreport(crewnames, crewstatus, supplies, funds, traveled);

printf(" What would you like to do? "); printf("1 - Fish "); printf("2 - Rest "); printf("3 - Continue "); scanf("%d", &action);

if(action == 1) { supplies[0] += fish(); } else if(action == 2) { day--; rest(supplies, crewnames, crewstatus, &day); } else { traveled += distanceperday; supplies[0] = max(supplies[0] - countcrew(crewstatus) * 2, 0); event(crewnames, crewstatus, &day, supplies); } } day++; }

printf(" ");

//The final printout changes based on which condition broke the while loop if (countcrew(crewstatus) == 0) { printf("Your crew has perished in the search for treasure. :( ");

printstatus(crewnames, crewstatus); } else { printf("Your crew has made it safely to the island. ");

printstatus(crewnames, crewstatus);

if(supplies[3] >= countcrew(crewstatus)) printf("You have enough shovels to dig up the treasure! "); else printf("Unfortuantely, you will not be able to dig up the treasure. "); }

return 0; }

//Pre-conditions: none //Post-conditions: each input parameter should be assigned an initial value

//What to do in this function: Provide the starting message for the user and ask how they plan to travel. // Based on their response initialize captaintype, funds, and distanceperday // -captaintype 1 should get 1000 funds and 80 distanceperday // -captaintype 2 should get 900 funds and 90 distanceperday // -captaintype 3 should get 800 funds and 100 distanceperday

// Ask the user for their name. Place this in the first row of crewnames, representing the captain. Treat // crewnames as a 1-Dimensional array of strings. As an example: printf("%s", crewnames[0]); would print the // first string or the captains name to the screen. Then ask for the names of the other 4 crew members in a loop.

// Set the crew status to 2 for each crew member, representing healthy // Set the initial amount of supplies to be 0 for each supply void setup(char crewnames[NUMCREW][STRLENGTH], int crewstatus[NUMCREW], int supplies[NUMSUPPLIES], int *captaintype, int *funds, int *distanceperday) {

}

//Pre-conditions: crewstatus is an array of numerical indicators for the status of each crew member // 0 - deceased, 1 - ill, 2 - healthy //Post-conditions: returns the number of crew members that are alive

//What to do in this function: Traverse the crew status array and count how many crew members // have a status that is not 0. Return this count. int countcrew(int crewstatus[NUMCREW]) {

}

//Pre-conditions: crew names is an array of strings for the crew members // crewstatus is an array of numerical indicators for the status of each crew member // 0 - deceased, 1 - ill, 2 - healthy //Post-conditions: none

//What to do in this function: print each crew members name and their status. // You may use a status array to shorten this process: char status[3][STRLENGTH] = {"Deceased", "Ill", "Healthy"}; void printstatus(char crewnames[NUMCREW][STRLENGTH], int crewstatus[NUMCREW]) {

}

//Pre-conditions: supplytypes in an array of strings and gives the name of each supply type // supplies is an array of integers representing how many of each type the crew has // funds represents how many gold pieces the crew has to spend //Post-conditions: the user may choose to buy supplies: incrementing values in supplies and // decrementing funds

//What to do in this function: First print out the amount of gold the crew has. // Then print each supply type and the amount it costs. You may use a cost array to shorten // this process: int supplycosts[NUMSUPPLIES] = {1, 2, 20, 10}; // Based on the user's selection, ask the user how many of that supply they would like to buy. // Verify that the user has enough gold for their purchase and update the correct index of supplies. // Deduct the corresponding amount from the user's funds. void getsupplies(char supplytypes[NUMSUPPLIES][STRLENGTH], int supplies[NUMSUPPLIES], int *funds) {

}

//Pre-conditions: crew names is an array of strings for the crew members // crewstatus is an array of numerical indicators for the status of each crew member // 0 - deceased, 1 - ill, 2 - healthy // supplies is an array of integers representing how many of each type the crew has // funds represents how many gold pieces the crew has to spend // traveled represents the total number of miles the ship has traveled from the beginning //Post-conditions: none

//What to do in this function: Print a daily status report by telling the user how many miles have been // traveled. Then, print the status of the crew by calling printstatus. Print the funds and amount // of food that the ship has. Then, let the user know how far they are from their next destination. void dailyreport(char crewnames[NUMCREW][STRLENGTH], int crewstatus[NUMCREW], int supplies[NUMSUPPLIES], int funds, int traveled) {

}

//Pre-conditions: a and b are both integers //Post-conditions: the larger value will be returned int max(int a, int b) {

}

//Pre-conditions: a and b are both integers //Post-conditions: the smaller value will be returned int min(int a, int b) {

}

//Pre-conditions: supplies is an array of integers representing how many of each type the crew has // crew names is an array of strings for the crew members // crewstatus is an array of numerical indicators for the status of each crew member // 0 - deceased, 1 - ill, 2 - healthy // days represents the current day //Post-conditions: the user will select a number of days to rest for. update days to reflect this number // there is a small chance an ill crew member will recover during rest days

//What to do in this function: ask the user how many days they would like to rest for. // Updates days to indicate that that many days has now passed. Deduct 2 pounds of food // for each crew member for each day rested.

// Generate a pseudorandom value that will be either 0 or 1. Generate a second value // between 0 and the number of original crew members. If the first number is a 1, // the crew member in the index of the second number may recover if they are sick. // If they are healthy or deceased, nothing happens. If the first number is a 0, // nothing happens. void rest(int supplies[NUMSUPPLIES], char crewnames[NUMCREW][STRLENGTH], int crewstatus[NUMCREW], int *days) {

}

//Pre-conditions: none //Post-conditions: returns the number of pounds of fish gained by the ship

//What to do in this function: Generate a pseudorandom value between 0 and 3, inclusive. // Multiply this number by 50 and tell the user how many fish were caught. Return // this value. int fish() {

}

//Pre-conditions: crew names is an array of strings for the crew members // crewstatus is an array of numerical indicators for the status of each crew member // 0 - deceased, 1 - ill, 2 - healthy // days represents the current day // supplies is an array of integers representing how many of each type the crew has //Post-conditions: the status of a crew member or supplies may be affected by a random event, // some events cause the ship to be delayed a certain number of days

//What to do in this function: Generate a pseudorandom number between 0 and 9, inclusive. If the user // has run out of food, tell the user they have no food and increase your number by 2. This number cannot // exceed 9.

// Numbers 0, 1, and 2 do not correspond with any events. // Numbers 3 and 4 correspond with "positive events" // on a 3 the user will gain between 1 and 4 ship parts determined randomly // on a 4 the user will gain between 10 and 60 pounds of food determined randomly // both events take 1 day // Number 5 means the user will lose between 5 and 55 pounds of food // this event takes 1 day // Number 6 means the ship is stuck in fog, which takes 1 day // Number 7 means the ship is in a storm, which takes 2 days // Number 8 means something on the ship has broken // check the number of extra ship parts the crew has // if they have at least one ship part, they can replace it and continue // this takes 1 day // if they have no extra parts, they must stop and repair // this takes 3 days // Number 9 indicates sickness. Generate a random number between 0 and the original // number of crew members. Check the status of that crew member: if they are healthy, // they now fall ill. If they are already ill, they now perish. If they are already // deceased, nothing happens.

// For any days spent in this way, deduct 2 pounds of food per crew member per day. void event(char crewnames[NUMCREW][STRLENGTH], int crewstatus[NUMCREW], int *days, int supplies[NUMSUPPLIES]) {

}

Instructions for the project -

Objectives

1. To learn how to write functions given specifications

2. To learn how to the use pass by value and pass by reference variables

3. Review previous concepts like if-statements and loops.

Introduction: Pirate Time

Your friend has not stopped talking about how cool pirates and how awesome it would be if they could be a real-life pirate captain! To amuse your friend, you have decided to create a series of programs about pirates.

Problem: Ocean Voyage (oceanvoyage.c)

Armed with the map from the Old Pirates Treasure Chest, plenty of oranges, and the best landing crew possible, your friend is ready to depart Spain for the Caribbean in search of treasure. The trip will be long and dangerous.

Your friend must decide how they will travel: as a merchant, as a privateer, or as a pirate. Merchant vessels are fairly safe, but slow. Merchant sailors will be given extra gold for their journey from their investors at home. Privateer vessels are well armed and a bit faster. Financed by the government, privateers will also receive a little extra gold for the trip. Pirates have the fastest ships in the seas, but only have the gold they already possess.

As captain, your friend has decided to depart from Port Marin, Spain. They will travel along the coast of Spain and Portugal and make for the Canary Islands. They will be able to buy supplies in both of these ports. From the Canary Islands they can catch the trade winds to Grenada at the edge of the Caribbean Sea. This will be the last opportunity to get supplies before searching for the island on the Old Pirates map.

Between ports there are many dangers. Sailors may fall ill, storms and fog may plague the ship, and parts of the ship may even break down. These will cause delays and your friend must balance the need to get to the treasure with the need to keep their crew healthy. Make sure they purchase plenty of food and extra parts for the journey.

At the end of the journey your friend will note how many of the crew survived the trip and how many shovels they managed to bring to dig up the treasure.

Lines for output -

Opening Text: You may now take your ship and crew from Port Marin, Spain to the hidden island in the Caribbean on the old pirate's map.

How will you travel? 1 - As a merchant 2 - As a privateer 3 - As a pirate

Captain Choices: As a merchant, you begin your trip with 1000 gold pieces. You will be sailing your Carrack, with an average speed of 80 miles per day.

As a privateer, you begin your trip with 900 gold pieces. You will be sailing your Galleon, with an average speed of 90 miles per day.

As a pirate, you begin your trip with 800 gold pieces. You will be sailing your Clipper, with an average speed of 100 miles per day.

Crew Names: What is your name, Captain? Who are the other members of your crew?

Crew Status: : : : : :

Buying Supplies: You have X gold pieces. Available Supples: 1. Food - 1 gold pieces 2. Clothes - 2 gold pieces 3. Ship Parts - 20 gold pieces 4. Shovels - 10 gold pieces 5. Leave Store

Food How many pounds of food do you want to buy? Sorry, you cannot afford that much food.

Clothes How many sets of clothes do you want to buy? Sorry, you cannot afford that many sets of clothes.

Ship Parts How many extra ship parts do you want to buy? Sorry, you cannot afford that many ship parts.

Shovels How many shovels do you want to buy? Sorry, you cannot afford that many shovels.

Daily Report You have traveled W miles. Crew Status You have X gold pieces. You have Y pounds of food. You are Z miles from your next destination.

Resting: How many days would you like to rest for? has recovered.

Fishing: Your crew lowers the nets and pulls up X pounds of fish.

Event (no food): You have no food.

Event (3): Another pirate ship pulls alongside and attacks! You fend them off and take X extra ship parts. You spend the day recovering.

Event (4): Another pirate ship pulls alongside and attacks! You fend them off and take X pounds of their food. You spend the day recovering.

Event (5): Another pirate ship pulls alongside and attacks! They took X pounds of food and you spend the day recovering.

Event (6): Fog surrounds your ship. Drop anchor for one day.

Event (7): An ocean storm batters your ship. Drop anchor for two days.

Event (8, parts available): A part of your ship has broken! You replace the broken part. It takes one day.

Event (8, no parts): A part of your ship has broken! You have no replacement parts. It takes three days to repair.

Event (9, getting ill): has fallen ill.

Event (9, dying): has died.

example output -

You may now take your ship and crew from Port Marin, Spain to the hidden island in the Caribbean on the old pirate's map.

How will you travel? 1 - As a merchant 2 - As a privateer 3 - As a pirate 1 As a merchant, you begin your trip with 1000 gold pieces. You will be sailing your Carrack, with an average speed of 80 miles per day.

What is your name, Captain? Sarah Who are the other members of your crew? 1:Tyler 2:Patrick 3:Mesut 4:Zack

Before leaving Port Marin, you should purchase some supplies.

You have 1000 gold pieces. Available Supples: 1. Food - 1 gold pieces 2. Clothes - 2 gold pieces 3. Ship Parts - 20 gold pieces 4. Shovels - 10 gold pieces 5. Leave Store 4 How many shovels do you want to buy? 5

You have 950 gold pieces. Available Supples: 1. Food - 1 gold pieces 2. Clothes - 2 gold pieces 3. Ship Parts - 20 gold pieces 4. Shovels - 10 gold pieces 5. Leave Store 3 How many extra ship parts do you want to buy? 6

You have 830 gold pieces. Available Supples: 1. Food - 1 gold pieces 2. Clothes - 2 gold pieces 3. Ship Parts - 20 gold pieces 4. Shovels - 10 gold pieces 5. Leave Store 2 How many sets of clothes do you want to buy? 5

You have 820 gold pieces. Available Supples: 1. Food - 1 gold pieces 2. Clothes - 2 gold pieces 3. Ship Parts - 20 gold pieces 4. Shovels - 10 gold pieces 5. Leave Store 1 How many pounds of food do you want to buy? 800

You have 20 gold pieces. Available Supples: 1. Food - 1 gold pieces 2. Clothes - 2 gold pieces 3. Ship Parts - 20 gold pieces 4. Shovels - 10 gold pieces 5. Leave Store 3 How many extra ship parts do you want to buy? 4 Sorry, you cannot afford that many ship parts.

You have 20 gold pieces. Available Supples: 1. Food - 1 gold pieces 2. Clothes - 2 gold pieces 3. Ship Parts - 20 gold pieces 4. Shovels - 10 gold pieces 5. Leave Store 5

--It is day #1.-- You have traveled 0 miles. Sarah: Healthy Tyler: Healthy Patrick: Healthy Mesut: Healthy Zack: Healthy

You have 20 gold pieces. You have 800 pounds of food. You are 1261 miles from your next destination.

What would you like to do? 1 - Fish 2 - Rest 3 - Continue 3 Another pirate ship pulls alongside and attacks! You fend them off and take 4 extra ship parts. You spend the day recovering.

--It is day #3.-- You have traveled 80 miles. Sarah: Healthy Tyler: Healthy Patrick: Healthy Mesut: Healthy Zack: Healthy

You have 20 gold pieces. You have 790 pounds of food. You are 1181 miles from your next destination.

What would you like to do? 1 - Fish 2 - Rest 3 - Continue 3 Patrick has fallen ill.

.

.

.

(skipping middle portion which is the same from the first day)

--It is day #123.-- You have traveled 4691 miles. Sarah: Healthy Tyler: Ill Patrick: Healthy Mesut: Deceased Zack: Healthy

You have 0 gold pieces. You have 161 pounds of food. You are 180 miles from your next destination.

What would you like to do? 1 - Fish 2 - Rest 3 - Continue 2 How many days would you like to rest for? 2686320

--It is day #124.-- You have traveled 4691 miles. Sarah: Healthy Tyler: Ill Patrick: Healthy Mesut: Deceased Zack: Healthy

You have 0 gold pieces. You have 153 pounds of food. You are 180 miles from your next destination.

What would you like to do? 1 - Fish 2 - Rest 3 - Continue 3 Another pirate ship pulls alongside and attacks! You fend them off and take 51 pounds of their food. You spend the day recovering.

--It is day #126.-- You have traveled 4771 miles. Sarah: Healthy Tyler: Ill Patrick: Healthy Mesut: Deceased Zack: Healthy

You have 0 gold pieces. You have 196 pounds of food. You are 100 miles from your next destination.

What would you like to do? 1 - Fish 2 - Rest 3 - Continue 3

--It is day #127.-- You have traveled 4851 miles. Sarah: Healthy Tyler: Ill Patrick: Healthy Mesut: Deceased Zack: Healthy

You have 0 gold pieces. You have 188 pounds of food. You are 20 miles from your next destination.

What would you like to do? 1 - Fish 2 - Rest 3 - Continue 3 A part of your ship has broken! You replace the broken part. It takes one day.

Your crew has made it safely to the island. Sarah: Healthy Tyler: Ill Patrick: Healthy Mesut: Deceased Zack: Healthy You have enough shovels to dig up the treasure!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!