Question:
I need help with a microsoft visual c# studios?
Madison P
2011-02-04 18:28:48 UTC
So I am taking my first programing class in college, I like it so far but I've hit a road block with my current assignment. here is the problem:

Captain Jack and his crew of pirates arrive in Tortuga after several weeks of plundering the high seas. Since the crew has been at sea for nearly a month, they are ready for a night of celebration. Captain Jack doesn't want to divvy up the treasure just yet, so he gives each man in the crew (except for himself and the first mate) 3 pieces of gold and sends them into town to celebrate. After the crew has gone he and the first mate count what's left and decide how to split it up among the crew. Captain Jack decides that he'll take 12% of the gold. He counts out his gold and hides it in his cabin. The Captain agrees to give the first mate 8% of the remaining gold. The first mate counts out his coins and hides it in his cabin. The next morning, the gold that is left is divided evenly among the members of the crew, including Captain Jack and the First Mate. Little do they know that Cap'n Jack and the first mate have already taken a cut. If the remaining treasure can't be split evenly, the bits that are left over are given to the Pirate's Benevolent Association.

The problem is to compute how much gold each person gets, and if any, how much goes to the Pirate's Benevolent Association. Keep in mind that a piece of gold cannot be split, so if some calculation yields a number that contains a fractional part, you can only give that person the integer part of the value. For example, if your program computed the captain's share as 25.67 pieces of gold, you could only give him 25 pieces of gold, not 25.67 pieces of gold. Warning, when you do any calculations do not round up. Simply drop the fractional part.

Your program should ask the user for two pieces of information:

* How much gold the pirate ship came into port with, and
* How many pirates are on the ship, including Captain Jack and the first mate.

Your program will then calculate and print how much gold the captain gets, how much the first mate gets, and how much each of the rest of the crew get. Finally, print out how much goes to the Pirate's Benevolent fund.

So I was able to calculate Jack's and the first mate's share, but when I got to the crew and the Pirate's Benevolent fund, I am stumped. Please help.
Three answers:
Krissfer linden
2011-02-04 19:08:43 UTC
I recommend you to use a modulus and maybe convert those values to int so that each of the values inserted each variables are constantly integers. I have the code here now using a console application. Hope you can understand my comments here.



//input for gold pieces

int gold = int.Parse(Console.ReadLine());

//input for number of crews

int crews = int.Parse(Console.ReadLine());

//calculating Captain's secret share (12%)

int jack = (int)(gold * .12);

//calculating First mate's secret share (8%)

int mate1 = (int)((gold - jack) * .08);

//displaying Jack's and 1st mate's secret share

Console.WriteLine("Jack (unadded equal share)= " + jack);

Console.WriteLine("First Mate (unadded equal share)= " + mate1);

//remaining gold after they get their secret share

gold = gold - (jack + mate1);

//calculating their equal share of gold

int perpirate = (int)(gold / crews);

//added share of jack after he receives his equal share

jack += perpirate;

//added share of 1st mate after he receives his equal share

mate1 += perpirate;

//to be given to pirate's benevolent fund

int reserve = gold % crews;

Console.WriteLine("Jack (added equal share)= "+ jack);

Console.WriteLine("First Mate (added equal share)= " + mate1);

Console.WriteLine("Each crew = " + perpirate);

Console.WriteLine("Reserve = " + reserve);

Console.ReadLine();
2016-08-20 04:42:29 UTC
I always spend my half an hour to read this blog's posts daily along with a mug of coffee.
patience
2016-09-20 03:05:45 UTC
Wow, Thanks! Exactly what I was looking for. I looked for the answers on the internet but I couldn't find them.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...