Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
added 126 characters in body
Source Link
Cliff B
  • 69.3k
  • 4
  • 33
  • 56

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

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

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

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

    // TODO: Prompt for end size
    float endSize;
    do
    {
        endSize = get_int("End Size: " );
    }
    while (endSize < startSize);

    // TODO: Calculate number of years until we reach threshold
    int years = 0;
    while (startSize < endSize)
    {
        startSize += (float) startSize / 12;
        years++;
    }
    // TODO: Print number of years
    printf("Years: %i\n", years);
}

}

These are the error I get:

:( rejects invalid populations and then handles population 9 expected "Years: 8", not "Years: 9\n" :( rejects invalid populations and then handles population 20 expected "Years: 20", not "Years: 21\n" :( handles starting population of 100 expected "Years: 115", not "Years: 116\n"

:( rejects invalid populations and then handles population 9
    expected "Years: 8", not "Years: 9\n"
:( rejects invalid populations and then handles population 20
    expected "Years: 20", not "Years: 21\n"
:( handles starting population of 100
    expected "Years: 115", not "Years: 116\n"

It looks like I am getting an extra year. Please help?

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

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

// TODO: Prompt for end size
float endSize;
do
{
    endSize = get_int("End Size: " );
}
while (endSize < startSize);

// TODO: Calculate number of years until we reach threshold
int years = 0;
while (startSize < endSize)
{
    startSize += (float) startSize / 12;
    years++;
}
// TODO: Print number of years
printf("Years: %i\n", years);

}

These are the error I get:

:( rejects invalid populations and then handles population 9 expected "Years: 8", not "Years: 9\n" :( rejects invalid populations and then handles population 20 expected "Years: 20", not "Years: 21\n" :( handles starting population of 100 expected "Years: 115", not "Years: 116\n"

It looks like I am getting an extra year. Please help?

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

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

    // TODO: Prompt for end size
    float endSize;
    do
    {
        endSize = get_int("End Size: " );
    }
    while (endSize < startSize);

    // TODO: Calculate number of years until we reach threshold
    int years = 0;
    while (startSize < endSize)
    {
        startSize += (float) startSize / 12;
        years++;
    }
    // TODO: Print number of years
    printf("Years: %i\n", years);
}

These are the error I get:

:( rejects invalid populations and then handles population 9
    expected "Years: 8", not "Years: 9\n"
:( rejects invalid populations and then handles population 20
    expected "Years: 20", not "Years: 21\n"
:( handles starting population of 100
    expected "Years: 115", not "Years: 116\n"

It looks like I am getting an extra year. Please help?

Source Link
Ben
  • 1
  • 1

This is my code for the Population problem and I can't figure out why my code is failing. It seems that I am getting one more year than the required

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

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

// TODO: Prompt for end size
float endSize;
do
{
    endSize = get_int("End Size: " );
}
while (endSize < startSize);

// TODO: Calculate number of years until we reach threshold
int years = 0;
while (startSize < endSize)
{
    startSize += (float) startSize / 12;
    years++;
}
// TODO: Print number of years
printf("Years: %i\n", years);

}

These are the error I get:

:( rejects invalid populations and then handles population 9 expected "Years: 8", not "Years: 9\n" :( rejects invalid populations and then handles population 20 expected "Years: 20", not "Years: 21\n" :( handles starting population of 100 expected "Years: 115", not "Years: 116\n"

It looks like I am getting an extra year. Please help?