472,146 Members | 1,212 Online

# This is My HW,PLS Help me!

On the planet Zephod, which orbits the star Betelgeuse, the sharks
increase at a rate of 5% of the guppy population per day, provided
there are 50 or more guppies per shark. Otherwise, the sharks die off
at a rate of 50% per day. The guppies increase at a rate of 80% per
day, provided the shark population is less than 20 % of the guppy
population. Otherwise there is no increase in the guppy population.
Each shark eats 5 guppies a day. Write a C program that allows the user
to input the initial shark population, the initial guppy population,
and the number of days of observation is to cover. The program is to
output a day-by-day account of the populations until one of them dies
off or the end of the observation period is reached. All reproductions
and deaths occur overnight. Any fractional fish are discarded. (These
sharks only feed during the day.)

Sample run:

Please enter number of sharks: 54
Please enter number of guppies: 1000
Number of days to observe: 15

Start of day 1 sharks 54 guppies 1000
End of day 1 sharks 54 guppies 730
Start of day 2 sharks 27 guppies 1314
Apr 6 '06 #1
20 2522
"Dj_TRuST" <dj*********@gmail.com> wrote in news:11**********************@i40g2000cwc.googlegr oups.com:

See

--
A. Sinan Unur <1u**@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
Apr 6 '06 #2
Dj_TRuST wrote:
On the planet Zephod, which orbits the star Betelgeuse, the sharks
increase at a rate of 5% of the guppy population per day, provided
there are 50 or more guppies per shark. Otherwise, the sharks die off
at a rate of 50% per day. The guppies increase at a rate of 80% per
day, provided the shark population is less than 20 % of the guppy
population. Otherwise there is no increase in the guppy population.
Each shark eats 5 guppies a day. Write a C program that allows the user
to input the initial shark population, the initial guppy population,
and the number of days of observation is to cover. The program is to
output a day-by-day account of the populations until one of them dies
off or the end of the observation period is reached. All reproductions
and deaths occur overnight. Any fractional fish are discarded.

This is a shame, the fractional fish are the tastiest.

S.
Apr 6 '06 #3

Skarmander wrote:
Dj_TRuST wrote:
On the planet Zephod, which orbits the star Betelgeuse, the sharks
increase at a rate of 5% of the guppy population per day, provided
there are 50 or more guppies per shark. Otherwise, the sharks die off
at a rate of 50% per day. The guppies increase at a rate of 80% per
day, provided the shark population is less than 20 % of the guppy
population. Otherwise there is no increase in the guppy population.
Each shark eats 5 guppies a day. Write a C program that allows the user
to input the initial shark population, the initial guppy population,
and the number of days of observation is to cover. The program is to
output a day-by-day account of the populations until one of them dies
off or the end of the observation period is reached. All reproductions
and deaths occur overnight. Any fractional fish are discarded.
This is a shame, the fractional fish are the tastiest.

You eat chum?

S.

Apr 6 '06 #4
"Dj_TRuST" <dj*********@gmail.com> wrote in message
((..description and sample run omitted..))

OK. I've got a program which produces the same* output as your sample run.
So, it's apparently solvable.

Let's your attempt and we'll see where the problems are.

- Bill
_______________
Except that I didn't bother making the numbers line up, so I've got:
C:\>sharks
Number of days to observe:15
Start of day 1, sharks 54, guppies 1000
End of day 1, sharks 54, guppies 730
Start of day 2, sharks 27, guppies 1314
End of day 2, sharks 27, guppies 1179
.... and so on...
Apr 7 '06 #5
"Dj_TRuST" writes:
On the planet Zephod, which orbits the star Betelgeuse, the sharks
increase at a rate of 5% of the guppy population per day, provided
there are 50 or more guppies per shark. Otherwise, the sharks die off
at a rate of 50% per day. The guppies increase at a rate of 80% per
day, provided the shark population is less than 20 % of the guppy
population. Otherwise there is no increase in the guppy population.
Each shark eats 5 guppies a day. Write a C program that allows the user
to input the initial shark population, the initial guppy population,
and the number of days of observation is to cover. The program is to
output a day-by-day account of the populations until one of them dies
off or the end of the observation period is reached. All reproductions
and deaths occur overnight. Any fractional fish are discarded. (These
sharks only feed during the day.)

There's a lot of words there. Sometimes it is helpful to sketch out a
solution of sorts. Here is pseudode influenced by the target
language, C. No guarantees but I hope it is right, does this help you get
started?

print start of day message
for (day = 1; day<n_days; day++)
sharks eat guppies during the day;
print end of day message
if guppies <= 0 print message and exit
sharks are born or die at night
(guppies don't die. they may be eaten during the day)
guppies may be born at night
print start of day message (day+1)
if sharks <= 0 print message and exit
Apr 7 '06 #6
On 2006-04-06, Dj_TRuST wrote:
What part of the problem couldn't you do?

If you break it down into parts, each part is quite simple.
On the planet Zephod, which orbits the star Betelgeuse, the sharks
increase at a rate of 5% of the guppy population per day, provided
there are 50 or more guppies per shark. Otherwise, the sharks die off
at a rate of 50% per day. The guppies increase at a rate of 80% per
day, provided the shark population is less than 20 % of the guppy
population. Otherwise there is no increase in the guppy population.
Each shark eats 5 guppies a day. Write a C program that allows the user
to input the initial shark population, the initial guppy population,
and the number of days of observation is to cover. The program is to
output a day-by-day account of the populations until one of them dies
off or the end of the observation period is reached. All reproductions
and deaths occur overnight. Any fractional fish are discarded. (These
sharks only feed during the day.)

Sample run:

Please enter number of sharks: 54
Please enter number of guppies: 1000
Number of days to observe: 15

Start of day 1 sharks 54 guppies 1000
End of day 1 sharks 54 guppies 730
Start of day 2 sharks 27 guppies 1314
.
.
.

I implemented it as a shell script. This is the body of the script
which calls a number of functions whose names should tell you what
they do:

init
day=0
while [ \$day -lt \$duration ]
do
day=\$(( \$day + 1 ))
time=Start
print_it
exit_test
guppy_gobble
time=End
print_it
exit_test
guppy_increase
shark_change
done

Here's a sample run:

Please enter number of sharks: 54
Please enter number of guppies: 1000
Number of days to observe: 15
Start of day 1 54 sharks 1000 guppies
End of day 1 54 sharks 730 guppies
Start of day 2 27 sharks 1314 guppies
End of day 2 27 sharks 1179 guppies
Coding it in C should be simple.

--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
Apr 7 '06 #7
me********@aol.com wrote:
Skarmander wrote:
Dj_TRuST wrote:
On the planet Zephod, which orbits the star Betelgeuse, the sharks
increase at a rate of 5% of the guppy population per day, provided
there are 50 or more guppies per shark. Otherwise, the sharks die off
at a rate of 50% per day. The guppies increase at a rate of 80% per
day, provided the shark population is less than 20 % of the guppy
population. Otherwise there is no increase in the guppy population.
Each shark eats 5 guppies a day. Write a C program that allows the user
to input the initial shark population, the initial guppy population,
and the number of days of observation is to cover. The program is to
output a day-by-day account of the populations until one of them dies
off or the end of the observation period is reached. All reproductions
and deaths occur overnight. Any fractional fish are discarded.

This is a shame, the fractional fish are the tastiest.

You eat chum?

The sharks certainly would. And, hey, if there was nothing else, and I had
ketchup...

S.
Apr 7 '06 #8
I state to use Borland C++
For ex:
#include <stdio.h>
int main()
{
int guppy,shark,day,n;
printf ("Please enter number of sharks: ");
scanf ("%d",&shark);
printf ("Please enter number of guppies: ");
scanf ("%d",&guppy);
printf ("Number of days to observe: ");
scanf ("%d",&n);
for (day=1;day<=n;day++)
{
printf ("Start of day %d sharks %d

Like that.PLS PLS Huryy up!!
Nextday i must give hw..

Apr 7 '06 #9

Dj_TRuST wrote:
I state to use Borland C++
For ex:
#include <stdio.h>
int main()
int main(void)
{
int guppy,shark,day,n;
printf ("Please enter number of sharks: ");
This potentially outputs nothing, as you didn't terminate it with '\n'.
scanf ("%d",&shark);
printf ("Please enter number of guppies: ");
Likewise...
scanf ("%d",&guppy);
printf ("Number of days to observe: ");
Likewise...
scanf ("%d",&n);
You have no sanity check for the values enetered, let alone checking
whether anything sensible has been entered at all.
for (day=1;day<=n;day++)
{
printf ("Start of day %d sharks %d
This does not compile at all...
Like that.PLS PLS Huryy up!!
Nextday i must give hw..

So what? Did you pay anyone here for service, fast or otherwise?

Nobody's going to do your (home)work for you. Especially not, if you
to put some *real* work, and thought into this.

Apr 7 '06 #10
"Dj_TRuST" writes:
I state to use Borland C++
For ex:
#include <stdio.h>
int main()
{
int guppy,shark,day,n;
printf ("Please enter number of sharks: ");
scanf ("%d",&shark);
printf ("Please enter number of guppies: ");
scanf ("%d",&guppy);
printf ("Number of days to observe: ");
scanf ("%d",&n);
for (day=1;day<=n;day++)
{
printf ("Start of day %d sharks %d

Like that.PLS PLS Huryy up!!
Nextday i must give hw..

That looks promising, test it and continue adding to it. I suspect you have
Apr 7 '06 #11
Dj_TRuST wrote:

{
int guppy,shark,day,n;
printf ("Please enter number of sharks: ");

This potentially outputs nothing, as you didn't terminate it with '\n'.

Do you have to add a '\n' to be sure that the text will
be printed to the screen? In that case I guess it has something
to do with line buffering, or something like that, is that correct?

And if you want print text without a carriage return after it, how
would one accomplish that? fflush()?

/Edward
Apr 7 '06 #12
On Fri, 07 Apr 2006 18:20:39 GMT, Edward Gregor <ed****@hotmail.com>
wrote:
Dj_TRuST wrote:
{
int guppy,shark,day,n;
printf ("Please enter number of sharks: ");

This potentially outputs nothing, as you didn't terminate it with '\n'.

Do you have to add a '\n' to be sure that the text will
be printed to the screen? In that case I guess it has something
to do with line buffering, or something like that, is that correct?

Yes. You can override the default behavior with setvbuf(), of course.
And if you want print text without a carriage return after it, how
would one accomplish that? fflush()?

Yes. Although the behavior of a particular output device on a
particular system isn't specified by the standard.

--
Al Balmer
Sun City, AZ
Apr 7 '06 #13
[snips]

On Fri, 07 Apr 2006 18:20:39 +0000, Edward Gregor wrote:
printf ("Please enter number of sharks: ");

This potentially outputs nothing, as you didn't terminate it with '\n'.

Do you have to add a '\n' to be sure that the text will
be printed to the screen?

No, for two reasons:

1) Ain't no guarantee it's going to the screen
2) fflush(stdout) after the printf() should do the trick, too
Apr 11 '06 #14
Kelsey Bjarnason opined:
[snips]

On Fri, 07 Apr 2006 18:20:39 +0000, Edward Gregor wrote:
Dj_TRuST wrote:

printf ("Please enter number of sharks: ");

This potentially outputs nothing, as you didn't terminate it with
'\n'.

Do you have to add a '\n' to be sure that the text will
be printed to the screen?

No, for two reasons:

1) Ain't no guarantee it's going to the screen
2) fflush(stdout) after the printf() should do the trick, too

Don't snip attribution lines. It should have looked as above...

--
"Today, of course, it is considered very poor taste to use the F-word
except in major motion pictures."
-- Dave Barry, "\$#\$%#^%!^%&@%@!"

<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>

Apr 11 '06 #15
[snps]

On Tue, 11 Apr 2006 07:58:49 +0100, Vladimir S. Oka wrote:
Don't snip attribution lines. It should have looked as above...

Leesee... somone named Edward Gregor wrote a post, I replied, with the
correct attribution "On Fri, 07 Apr 2006 18:20:39 +0000, Edward Gregor
wrote:"

What, pray tell, is wrong with that, since it correctly reflects the
poster's identity?
Apr 11 '06 #16
Kelsey Bjarnason opined:
[snps]

On Tue, 11 Apr 2006 07:58:49 +0100, Vladimir S. Oka wrote:
Don't snip attribution lines. It should have looked as above...

Leesee... somone named Edward Gregor wrote a post, I replied, with
the correct attribution "On Fri, 07 Apr 2006 18:20:39 +0000, Edward
Gregor wrote:"

What, pray tell, is wrong with that, since it correctly reflects the
poster's identity?

If embedded quotes are irrelevant, snip them as well (as you did
above). Since earlier you didn't, it makes it important to know who
said what. It takes almost the same effort as well (even less
probably).

--
There are no threads in a.b.p.erotica, so there's no gain in using a
(Unknown source)

<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>

Apr 11 '06 #17
[snips]

On Tue, 11 Apr 2006 10:40:43 +0100, Vladimir S. Oka wrote:
Don't snip attribution lines. It should have looked as above...
What, pray tell, is wrong with that, since it correctly reflects the
poster's identity?
If embedded quotes are irrelevant, snip them as well (as you did
above). Since earlier you didn't, it makes it important to know who
said what.

No, it doesn't. What matters is context. If one needs further details,
this is why God created news clients capable of handling more than one

Your news client must be broken. Not my problem. As a side note, this
has bugger all to do with topicality. If you want to continue, do it via
email.
Apr 11 '06 #18
Kelsey Bjarnason <kb********@gmail.com> writes:
[snips]

On Tue, 11 Apr 2006 10:40:43 +0100, Vladimir S. Oka wrote:
Don't snip attribution lines. It should have looked as above... What, pray tell, is wrong with that, since it correctly reflects the
poster's identity?

If embedded quotes are irrelevant, snip them as well (as you did
above). Since earlier you didn't, it makes it important to know who
said what.

No, it doesn't. What matters is context. If one needs further details,
this is why God created news clients capable of handling more than one

Your news client must be broken. Not my problem. As a side note, this
has bugger all to do with topicality. If you want to continue, do it via
email.

As you know (or should, because it's been discussed to death here),
Usenet is an asynchronous medium. It's not always possible to see
previous articles. Articles can arrive out of order or not at all,
and old articles expire at a rate that depends on the server's
settings and the amount of space available.

I happen to use a newsreader that makes it easy to see parent articles
*if* they're available. Nevertheless, I strongly prefer to see enough
context in each article to understand what's going on, or at least to
jog my memory.

If a followup includes quoted text from a previous article, it should
include an attribution line for that text, regardless of whether it's
a direct quote or an indirect one. Since it's easier to leave the
attribution lines in than to delete them, I fail to understand why
this is even an issue.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Apr 11 '06 #19
> > On Tue, 11 Apr 2006 10:40:43 +0100, Vladimir S. Oka wrote:
> Don't snip attribution lines. It should have looked as above... If embedded quotes are irrelevant, snip them as well (as you did
above). Since earlier you didn't, it makes it important to know who
said what.

No, it doesn't. What matters is context.

I think Keith Thompson's point is valid.

--
pete
Apr 12 '06 #20
Kelsey Bjarnason opined:
[snips]

On Tue, 11 Apr 2006 10:40:43 +0100, Vladimir S. Oka wrote:
Don't snip attribution lines. It should have looked as above... What, pray tell, is wrong with that, since it correctly reflects
the poster's identity?
If embedded quotes are irrelevant, snip them as well (as you did
above). Since earlier you didn't, it makes it important to know who
said what.

No, it doesn't. What matters is context.

Elsethread, pete gave you a very good example of how knowing who said
what matters.
If one needs further details, this is why God created news clients
I'm sure if (S)he really did they'd be perfect, and Usenet wouldn't be
asynchronous. Alas, this is not so...
capable of handling more than one article per thread,
But why would I have to trawl past articles, even if I could see them,
to find out who said what? Especially as that requires considerable
exercise of eyeball grep. OTH, it's actually less work for you to not
These, as they are now, we could do without, IMHO.
Your news client must be broken. Not my problem.
Possibly. True.
As a side note, this has bugger all to do with topicality. If you
want to continue, do it via email.

Discussions of posting styles and topicality itself are always topical.

--
Linux: Because a PC is a terrible thing to waste.
(By ko******@craft.camp.clarkson.edu, Mark Komarinski)

<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>

Apr 12 '06 #21

### This discussion thread is closed

Replies have been disabled for this discussion.