Hot answers tagged

2

You've got the right mindset, but think about this approach. Initiate a flag for velocity, this will dictate if the ball is moving or not. Initially it is 0, and the ball is at rest in the center. When a click event is noticed, the flag turns to 1, which triggers an if statement, giving the ball velocity. If the bottom is struck, turn the velocity flag to ...


1

A problem I found is at line 47 of the code (the second while loop): while (power <= 14) { sum += (number % 10); power += 2; number = number / pow(10,power); } I think you meant the line number = number / pow(10,power) to be: number = beginningNumber / pow(10,power) Otherwise the variable number does the following (during the second while ...


1

The infinite loop lies here: while(j < rows) { printf("#"); (i++); } The loop depends on the value of j being updated and eventually not less than rows. Since j is never changed inside the loop, one of two things happens. Either the loop doesn't start, or if it does, it never stops. There has to be something inside the loop that ...


1

So after you get an error message that says "Out of Range", when you try to enter another value that is out of range, the loop stops. There is a "clearKeyboard()" function that is called in here - this is to clear the buffer of the "\n" character as it creates problems for strings in C using scanf. After struggling with this for a good while, I thought ...


1

Error message is caused by your ; after int main (void), making it a function declaration rather than a function definition. For a function definition, a code block in curly braces follows that line, not a semicolon. Inside those braces is the code that belongs to the function. Function declaration (not required for main, as you would not call that yourself,...


1

Credit to Kareem for answering this question, but it has been 4 months and it hasn't been posted as an answer... in the interest of improving the CS50 knowledge base, I'm posting the answer here. (I arrived at this question by searching for unanswered questions to help with involving pset1.) 1 while (owed > quarter) 2 { 3 change++; 4 } printf("%...


1

You need to use malloc() here: char* title = "000.jpg"; so that your sprintf() can write to title safely. Here's an explanation: So how come that you get segmentation fault? - The main point is that char* title = "000.jpg"; makes title point to the read-only memory where your string literal "000.jpg" is stored. So when you try to access this ...


1

Simple problem. You put a semicolon in int main(void); The correct structure is: int main(void) { // code goes between curly braces } You also have a declaration statement, int n; before the first brace. The compiler assumes you mostly know what you are doing, so the two lines with main and int n which end in semicolons look like a function signature ...


1

This loop will run exactly once every time. Look at your test. It has to be true for the loop to execute more than once, but that will never happen. What number can be less than zero AND greater than 23 AT THE SAME TIME? ;-) If this answers your question, please click on the check to accept. Let's keep up on forum housekeeping. ;-)


1

You have a couple of issues in this code that are mostly about structure. First, the semicolon after the while condition serves as a statement terminator and basically means "While this condition is true, do nothing until it is false and then continue to the next line of code." In fact, if you entered a negative number, it should just sit there forever, ...


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