Skip to main content
5 votes
Accepted

Why is my lab1 code failing to pass one test in check50?

It's failing the test because you are using a do-while loop which is incrementing n before it checks if year < y. Remember that the reason to use a do-while loop instead of a while loop is that you ...
Robert S. Pratt's user avatar
1 vote

I don't what number means in PRIME/LAB1

In the code above, "number" is simply a variable name. It could easily have been "my_number" or "a_possible_prime" or even "fred" for that matter. The word &...
Cliff B's user avatar
  • 69.2k
1 vote
Accepted

My while loop runs an extra time (Lab 1)

It's failing on a corner case, specifically when the total at the end of the year is exactly the target population. If it were more, you'd get the correct answer. Look at the while loop setup: while (...
Cliff B's user avatar
  • 69.2k
1 vote

Lab 1 population growth

In C, integer division truncates. Any start value less than 12 will result in an infinite loop. Keeping truncation in mind, with start value 9, start += start / 12 evaluates to 9 because start / 12 ...
DinoCoderSaurus's user avatar
1 vote
Accepted

Can't seem to get total number of years to print properly in Lab 1

I see two serious problems here. First, the print statement is inside the for loop, so you're going to print something on every pass through the loop, or nothing at all if the loop doesn't execute. ...
Cliff B's user avatar
  • 69.2k
1 vote

cs50.h: No such file or directory

Looks like your codespace is in Recovery mode. Please follow the instructions here: https://cs50.readthedocs.io/code/#codespaces-run-into-recovery-mode
curiouskiwi's user avatar
  • 18.7k

Only top scored, non community-wiki answers of a minimum length are eligible