0

enter image description hereenter image description hereThis is my code

#include <cs50.h>
#include <stdio.h>

int main(void)
{
    // TODO: Prompt for start size
    
    int s;
    do
    {
        s= get_int("Start size: ");
    }
    
    while (s<9);

    // TODO: Prompt for end size
    
      int e;
    do
    {
       e=get_int("End size: ");
    }
    while (e<s);
    

    // TODO: Calculate number of years until we reach threshold
    
    int c =0;
    for(int i =0;i<=c & s<e;i++)
    {
    c++;
    s=s*13/12;
    }

    // TODO: Print number of years
    
    printf("Years: %i\n",c);

}
0

problem is here u cant make a fixed formula s=s*13/12; since its diffrent than using s=s+(s/3)-(s/4); and check , it wil give u all GREEN

4
  • Integer truncate division. Jan 26 at 2:58
  • OK, I've looked at the lab docs and discussed it with @curiouskiwi. Yes, while this code is "mathematically correct" in factoring out the s from each factor, it's an incorrect real world solution. As the lab says, you can't have a fractional llama! So, the code needs to do all the math. The integer division needs to be done for the number of llamas born and then for the number that die for each year. Since integer division truncates any fractional portion (it never rounds up), all those calculations can stack up, leading to a much different real world solutiion.
    – Cliff B
    Jan 26 at 3:07
  • Yes, @DinoCoderSaurus, I expected it would be an integer truncation issue, but wasn't sure where it came from until I studied the lab. Labs are new this year, and I haven't looked at them until now. ;-)
    – Cliff B
    Jan 26 at 3:07
  • Thanks so much for your reply. I got it. Thanks guys.
    – Aya Othman
    Jan 26 at 12:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .