Home > Blockchain >  CS50 Lab1 - Not printing anything
CS50 Lab1 - Not printing anything

Time:10-10

I am trying to do lab1 for CS50 for beginners. I am struggling to understand why my code is not working.

Asking the user for a start size and an end size works fine.

The problem is when I am calculating the years it takes to reach the final size, and then displaying the result. It doesn't work, and I cannot see why it is not working.

Can anyone see what I am doing wrong in my code? I have looked at similar questions, but I still cannot understand what I am doing wrong.

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

// Determine the number of years required for the population to grow from the start size to the end size.


int main(void)
{
    // TODO: Prompt for start size. Has to be greater than 9, otherwise ask again.
    // TODO: Prompt for end size
int start;
int end;
int years = 0;
int n;
do
{
    start=get_int("Give me a start size of the population: ");
    end=get_int("Give me a end size of the population: ");
    
}
while (start<9 || end<start);
return start;
return end;

    // TODO: Calculate number of years until we reach threshold

do
{
    n = start   (start/3)-(start/4);
    start=n;
    years  ;
}
 while (start<end);
 return years;

    // TODO: Print number of years

    printf("The number of years to reach your end population is %i/n", years);
}

CodePudding user response:

The line :

return start;

Exit the main More generally all returns you have in main will exit your program

CodePudding user response:

new is a reserved keyword. It's forbidden to use it as a variable name!

  • Related