Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. A c program to project expected number of rabbits on a farm

A c program to project expected number of rabbits on a farm

Scheduled Pinned Locked Moved C / C++ / MFC
business
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Arnold Mukisa
    wrote on last edited by
    #1

    Farmers want to be able to project business investment needs over a given period of time (in months). During
    the program development, you consult a Rabbit specialist who gives you certain facts about rabbits as stated
    below.
    i) A female rabbit is called doe, a male rabbit is a buck and baby rabbits are kittens.
    ii) Female rabbits take two months to mature and start mating. Once they start mating, they produce every
    month. On average, a single rabbit produces 8 kittens every time they produce.
    Assuming that the framers will only invest in female rabbits and that male rabbits will always be hired during matting
    period and their number is negligible. Assume that no rabbit dies on the farm and that they will all grow at the same
    rate.
    Write a c program that prompts the farmer to input the initial number of rabbits on the farm and the number of
    months the farmer wants to sustain the farm. The program should compute and print out the expected number of
    rabbits on the farm for each month until the last month.

    A D P 3 Replies Last reply
    0
    • A Arnold Mukisa

      Farmers want to be able to project business investment needs over a given period of time (in months). During
      the program development, you consult a Rabbit specialist who gives you certain facts about rabbits as stated
      below.
      i) A female rabbit is called doe, a male rabbit is a buck and baby rabbits are kittens.
      ii) Female rabbits take two months to mature and start mating. Once they start mating, they produce every
      month. On average, a single rabbit produces 8 kittens every time they produce.
      Assuming that the framers will only invest in female rabbits and that male rabbits will always be hired during matting
      period and their number is negligible. Assume that no rabbit dies on the farm and that they will all grow at the same
      rate.
      Write a c program that prompts the farmer to input the initial number of rabbits on the farm and the number of
      months the farmer wants to sustain the farm. The program should compute and print out the expected number of
      rabbits on the farm for each month until the last month.

      A Offline
      A Offline
      Arnold Mukisa
      wrote on last edited by
      #2

      Ive been able to write this but i feel it can be sized down and made better your direct ideas will be of much help as I am only abt 2weeks in c programming but hv been working very hard to learn thks take a look

      #include<stdio.h>
      int main()
      {
      int initialrabbits,no_months,Kittens[10],Rabbits,count=1,kits,totalkittens;
      printf("\nEnter initial no of rabbits:\a ");
      scanf("%d",&initialrabbits);

      printf("\\nEnter number of months to be projected:\\a ");
      scanf("%d",&no\_months);
      
          for(count=1;count<=no\_months;count++)
          {
              if (count==1){
              Kittens\[0\]=initialrabbits\*8;
              Rabbits=initialrabbits;
              kits=Kittens\[0\];
              totalkittens=Kittens\[0\];}
      
              else if (count==2){
              Kittens\[1\]=initialrabbits\*8;
              Rabbits=initialrabbits;
              kits=Kittens\[1\];
              totalkittens=Kittens\[0\]+Kittens\[1\];}
      
              else if (count==3){
              Kittens\[2\]=(Kittens\[0\]+initialrabbits)\*8;
              Rabbits=Kittens\[0\]+initialrabbits;
              kits=Kittens\[2\];
              totalkittens=Kittens\[1\]+Kittens\[2\];}
      
              else if (count==4){
              Kittens\[3\]=(Kittens\[0\]+Kittens\[1\]+initialrabbits)\*8;
              Rabbits=Kittens\[0\]+Kittens\[1\]+initialrabbits;
              kits=Kittens\[3\];
              totalkittens=Kittens\[2\]+Kittens\[3\];}
      
              else if (count==5){
              Kittens\[4\]=(Kittens\[0\]+Kittens\[1\]+Kittens\[2\]+initialrabbits)\*8;
              Rabbits=Kittens\[0\]+Kittens\[1\]+Kittens\[2\]+initialrabbits;
              kits=Kittens\[4\];
              totalkittens=Kittens\[3\]+Kittens\[4\];}
      
              else if (count==6){
              Kittens\[5\]=(Kittens\[0\]+Kittens\[1\]+Kittens\[2\]+Kittens\[3\]+initialrabbits)\*8;
              Rabbits=Kittens\[0\]+Kittens\[1\]+Kittens\[2\]+Kittens\[3\]+initialrabbits;
              kits=Kittens\[5\];
              totalkittens=Kittens\[4\]+Kittens\[5\];}
      
              else if (count==7){
              Kittens\[6\]=(Kittens\[0\]+Kittens\[1\]+Kittens\[2\]+Kittens\[3\]+Kittens\[4\]+initialrabbits)\*8;
              Rabbits=Kittens\[0\]+Kittens\[1\]+Kittens\[2\]+Kittens\[3\]+Kittens\[4\]+initialrabbits;
              kits=Kittens\[6\];
              totalkittens=Kittens\[5\]+Kittens\[6\];}
      
              else if (count==8){
              Kittens\[7\]=(Kittens\[0\]+Kittens\[1\]+Kittens\[2\]+Kittens\[3\]+Kittens\[4\]+Kittens\[5\]+initialrabbits)\*8;
              Rabbits=Kittens\[0\]+Kittens\[1\]+Kittens\[2\]+Kittens\[3\]+Kittens\[4\]+Kittens\[5\]+initialrabbit
      
      D 1 Reply Last reply
      0
      • A Arnold Mukisa

        Farmers want to be able to project business investment needs over a given period of time (in months). During
        the program development, you consult a Rabbit specialist who gives you certain facts about rabbits as stated
        below.
        i) A female rabbit is called doe, a male rabbit is a buck and baby rabbits are kittens.
        ii) Female rabbits take two months to mature and start mating. Once they start mating, they produce every
        month. On average, a single rabbit produces 8 kittens every time they produce.
        Assuming that the framers will only invest in female rabbits and that male rabbits will always be hired during matting
        period and their number is negligible. Assume that no rabbit dies on the farm and that they will all grow at the same
        rate.
        Write a c program that prompts the farmer to input the initial number of rabbits on the farm and the number of
        months the farmer wants to sustain the farm. The program should compute and print out the expected number of
        rabbits on the farm for each month until the last month.

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        See #11 here.

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

        1 Reply Last reply
        0
        • A Arnold Mukisa

          Ive been able to write this but i feel it can be sized down and made better your direct ideas will be of much help as I am only abt 2weeks in c programming but hv been working very hard to learn thks take a look

          #include<stdio.h>
          int main()
          {
          int initialrabbits,no_months,Kittens[10],Rabbits,count=1,kits,totalkittens;
          printf("\nEnter initial no of rabbits:\a ");
          scanf("%d",&initialrabbits);

          printf("\\nEnter number of months to be projected:\\a ");
          scanf("%d",&no\_months);
          
              for(count=1;count<=no\_months;count++)
              {
                  if (count==1){
                  Kittens\[0\]=initialrabbits\*8;
                  Rabbits=initialrabbits;
                  kits=Kittens\[0\];
                  totalkittens=Kittens\[0\];}
          
                  else if (count==2){
                  Kittens\[1\]=initialrabbits\*8;
                  Rabbits=initialrabbits;
                  kits=Kittens\[1\];
                  totalkittens=Kittens\[0\]+Kittens\[1\];}
          
                  else if (count==3){
                  Kittens\[2\]=(Kittens\[0\]+initialrabbits)\*8;
                  Rabbits=Kittens\[0\]+initialrabbits;
                  kits=Kittens\[2\];
                  totalkittens=Kittens\[1\]+Kittens\[2\];}
          
                  else if (count==4){
                  Kittens\[3\]=(Kittens\[0\]+Kittens\[1\]+initialrabbits)\*8;
                  Rabbits=Kittens\[0\]+Kittens\[1\]+initialrabbits;
                  kits=Kittens\[3\];
                  totalkittens=Kittens\[2\]+Kittens\[3\];}
          
                  else if (count==5){
                  Kittens\[4\]=(Kittens\[0\]+Kittens\[1\]+Kittens\[2\]+initialrabbits)\*8;
                  Rabbits=Kittens\[0\]+Kittens\[1\]+Kittens\[2\]+initialrabbits;
                  kits=Kittens\[4\];
                  totalkittens=Kittens\[3\]+Kittens\[4\];}
          
                  else if (count==6){
                  Kittens\[5\]=(Kittens\[0\]+Kittens\[1\]+Kittens\[2\]+Kittens\[3\]+initialrabbits)\*8;
                  Rabbits=Kittens\[0\]+Kittens\[1\]+Kittens\[2\]+Kittens\[3\]+initialrabbits;
                  kits=Kittens\[5\];
                  totalkittens=Kittens\[4\]+Kittens\[5\];}
          
                  else if (count==7){
                  Kittens\[6\]=(Kittens\[0\]+Kittens\[1\]+Kittens\[2\]+Kittens\[3\]+Kittens\[4\]+initialrabbits)\*8;
                  Rabbits=Kittens\[0\]+Kittens\[1\]+Kittens\[2\]+Kittens\[3\]+Kittens\[4\]+initialrabbits;
                  kits=Kittens\[6\];
                  totalkittens=Kittens\[5\]+Kittens\[6\];}
          
                  else if (count==8){
                  Kittens\[7\]=(Kittens\[0\]+Kittens\[1\]+Kittens\[2\]+Kittens\[3\]+Kittens\[4\]+Kittens\[5\]+initialrabbits)\*8;
                  Rabbits=Kittens\[0\]+Kittens\[1\]+Kittens\[2\]+Kittens\[3\]+Kittens\[4\]+Kittens\[5\]+initialrabbit
          
          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          No need to have all of the if/else conditions within the for() loop. Try something a bit leaner, like:

          #include <stdio.h>

          int main()
          {
          int initialrabbits,
          no_months,
          Kittens[10],
          Rabbits,
          kits,
          totalkittens = 0;

              printf("\\nEnter initial no of rabbits:\\a ");
              scanf("%d",&initialrabbits);
          
              printf("\\nEnter number of months to be projected:\\a ");
              scanf("%d",&no\_months);
          
              for(int count=0;count
          

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

          1 Reply Last reply
          0
          • A Arnold Mukisa

            Farmers want to be able to project business investment needs over a given period of time (in months). During
            the program development, you consult a Rabbit specialist who gives you certain facts about rabbits as stated
            below.
            i) A female rabbit is called doe, a male rabbit is a buck and baby rabbits are kittens.
            ii) Female rabbits take two months to mature and start mating. Once they start mating, they produce every
            month. On average, a single rabbit produces 8 kittens every time they produce.
            Assuming that the framers will only invest in female rabbits and that male rabbits will always be hired during matting
            period and their number is negligible. Assume that no rabbit dies on the farm and that they will all grow at the same
            rate.
            Write a c program that prompts the farmer to input the initial number of rabbits on the farm and the number of
            months the farmer wants to sustain the farm. The program should compute and print out the expected number of
            rabbits on the farm for each month until the last month.

            P Offline
            P Offline
            Paul Conrad
            wrote on last edited by
            #5

            Kittens are baby cats, kits are baby rabbits :) Now, to your question, what have you accomplished so far in the program?

            "I've seen more information on a frickin' sticky note!" - Dave Kreskowiak

            D 1 Reply Last reply
            0
            • P Paul Conrad

              Kittens are baby cats, kits are baby rabbits :) Now, to your question, what have you accomplished so far in the program?

              "I've seen more information on a frickin' sticky note!" - Dave Kreskowiak

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              Paul Conrad wrote:

              ...kits are baby rabbits

              Either designation is correct.

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups