This is My HW,PLS Help me!

D

Dj_TRuST

This is my homework and i couldn't do it,please help me.
I wait your helpsss
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
.
.
.
 
S

Skarmander

Dj_TRuST said:
This is my homework and i couldn't do it,please help me.
I wait your helpsss
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.
 
W

William J. Leary Jr.

Dj_TRuST said:
This is my homework and i couldn't do it,please help me.
((..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
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
End of day 2, sharks 27, guppies 1179
.... and so on...
 
O

osmium

Dj_TRuST said:
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
 
C

Chris F.A. Johnson

This is my homework and i couldn't do it,please help me.

What part of the problem couldn't you do?

If you break it down into parts, each part is quite simple.
I wait your helpsss
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.
 
D

Dj_TRuST

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

Vladimir S. Oka

Dj_TRuST said:
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
keep *demanding* someone helps. Go away, read your textbooks, and try
to put some *real* work, and thought into this.
 
O

osmium

Dj_TRuST said:
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
already had all the help you are going to receive from this newsgroup.
 
E

Edward Gregor

Vladimir said:
Dj_TRuST wrote:

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
 
A

Al Balmer

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

Kelsey Bjarnason

[snips]

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
 
V

Vladimir S. Oka

Kelsey Bjarnason opined:
[snips]

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

Kelsey Bjarnason

[snps]

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?
 
V

Vladimir S. Oka

Kelsey Bjarnason opined:
[snps]

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
threaded news reader.
(Unknown source)

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

Kelsey Bjarnason

[snips]

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
article per thread, Google groups and the like.

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

Keith Thompson

Kelsey Bjarnason said:
[snips]

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
article per thread, Google groups and the like.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top