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 ...
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 ...
The infinite loop lies here:
while(j < rows)
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 ...
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 ...
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,...
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)
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 ...
Simple problem. You put a semicolon in int main(void); The correct structure is:
// 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 ...
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. ;-)
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, ...