shegues

population.c

Jan 24th, 2021 (edited)
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. #include <cs50.h>
  2. #include <stdio.h>
  3.  
  4. int main(void)
  5. {
  6.     int start_size;
  7.     int end_size;
  8.     int years_passed;
  9.     // TODO: Prompt for start size
  10.     do
  11.     {
  12.         start_size = get_int("the starting population size is: ");
  13.     }
  14.     while (start_size < 9);
  15.     //return start_size;
  16.  
  17.     // TODO: Prompt for end size
  18.     do
  19.     {
  20.         end_size = get_int("the ending population size is: ");
  21.     }
  22.     while (end_size < start_size);
  23.     //return end_size;
  24.     // TODO: Calculate number of years until we reach threshold
  25.     int previous_size;
  26.     int actual_size = start_size;
  27.     int final_size;
  28.     years_passed = 0;
  29.     for(previous_size = start_size; actual_size < end_size; previous_size = previous_size + (previous_size / 3) - (previous_size / 4 ))
  30.     {
  31.         actual_size = previous_size + (previous_size / 3) - (previous_size / 4 );
  32.         years_passed += 1;
  33.     }
  34.     printf("years passed = %i\n", years_passed);
  35.     // TODO: Print number of years
  36. }
Add Comment
Please, Sign In to add comment