473,322 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

This is My HW,PLS Help me!

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
Apr 6 '06 #1
20 2634
"Dj_TRuST" <dj*********@gmail.com> wrote in news:11**********************@i40g2000cwc.googlegr oups.com:
This is my homework and i couldn't do it,please help me.


See

http://groups.google.com/group/comp....t=0&scoring=d&

--
A. Sinan Unur <1u**@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
Apr 6 '06 #2
Dj_TRuST wrote:
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.
Apr 6 '06 #3

Skarmander wrote:
Dj_TRuST wrote:
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.


You eat chum?

S.


Apr 6 '06 #4
"Dj_TRuST" <dj*********@gmail.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
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...
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:
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.

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


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
keep *demanding* someone helps. Go away, read your textbooks, and try
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
already had all the help you are going to receive from this newsgroup.
Apr 7 '06 #11
Vladimir S. Oka 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?

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:
Vladimir S. Oka 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:
Vladimir S. Oka 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
threaded news reader.
(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
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.
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
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.

--
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
snip attributions.
Google groups and the like.
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: James | last post by:
I have a from with 2 fields: Company & Name Depening which is completed, one of the following queries will be run: if($Company){ $query = "Select C* From tblsample Where ID = $Company...
5
by: Scott D | last post by:
I am trying to check and see if a field is posted or not, if not posted then assign $location which is a session variable to $location_other. If it is posted then just assign it to...
2
by: Nick | last post by:
Can someone please tell me how to access elements from a multiple selection list? From what ive read on other posts, this is correct. I keep getting an "Undefined variable" error though... Form...
2
by: Alexander Ross | last post by:
I have a variable ($x) that can have 50 different (string) values. I want to check for 7 of those values and do something based on it ... as I see it I have 2 options: 1) if (($x=="one") ||...
0
by: Dan Foley | last post by:
This script runs fine, but I'd like to know why it's so slow.. Thanks for any help out there on how i can make it faster (it might take up to 5 min to write these 3 export files whith 15 records...
5
by: Lee Redeem | last post by:
Hi there I've created abd uploaded this basic PHP script: <html> <head> <title>PHP Test</title> </head> <body> <H1 align="center">
5
by: christopher vogt | last post by:
Hi, i'm wondering if there is something like $this-> to call a method inside another method of the same class without using the classname in front. I actually use class TEST { function...
6
by: Phil Powell | last post by:
Ok guys, here we go again! SELECT s.nnet_produkt_storrelse_navn FROM nnet_produkt_storrelse s, nnet_produkt_varegruppe v, nnet_storrelse_varegruppe_assoc sv, nnet_produkt p WHERE...
1
by: Michel | last post by:
a site like this http://www.dvdzone2.com/dvd Can you make it in PHP and MySQL within 6 weeks? If so, send me your price 2 a r a (at) p a n d o r a . b e
11
by: Maciej Nadolski | last post by:
Hi! I can`t understand what php wants from me:( So: Cannot send session cache limiter - headers already sent (output started at /home/krecik/public_html/silnik.php:208) in...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.