3

The problem is bad structuring of the chain of ifs and else ifs. Look at the following: if(...) { ... } else if (isupper((char)*(word + i))) { else if (cursor -> children[(int)*(word + i) - 64] == NULL) { The first else if follows from the first if statement. There is an if statement, a block of code to execute when it is true, ...


1

#include <cs50.h> #include <math.h> int main(void) { int n = 0; do { n = (get_float("Change owed: ") * 100); } while (n < 0); int q = ((n / 25) % 10); //<- need semicolon to terminate each statement int d = ((q / 10) % 10); int r = ((d / 5) % 10); int c = (n % 10); int i = q + d + n + c; printf("%i", i); // <- ...


1

Your get_string() has no arguments, while in the lectures we've been taught to always insert a prompt (in the form of a string) in between the parentheses. Try combining these two lines: printf("plaintext: "); char* plaintext = get_string(); into this one liner: char* plaintext = get_string("plaintext: ");


1

An expression is something that returns a value, like strlen(argv[1]) or i++. This int n = strlen(argv[1]) is a declaration or assigment operator. In a for statement, only the first argument allows initialization/assignment. Program would also compile like so: for (int i = 0, n = strlen(argv[1]); i < n; i++) Similar to this example in the lecture: #...


1

These are all syntax errors. In the case of the first two, it's an incorrect initialization, more or less. I'll explain. in order to use the {...} technique, you have to do this at the same time as the array is created. int array[] = { 3 , 5 } would create an array of 2 integers and populate them with 3 and 5. However, int ...


1

If you adjusted the indentation to match the curly braces, you'd realise that you put the else after the for loop, not one level higher after the if. You don't need that outer if, as your for loop would do the same test. But it won't hurt either. You have a logical problem inside your for loop, as you always return in the first iteration. Don't stop the ...


1

The error is created by the compiler finding an else clause without knowing the corresponding if (there has to be exactly one statement or code block in between). Use {} blocks with your if to conditionally execute several statements, and never ever place a semicolon behind your if condition, that's the empty statement, you essentially tell the compiler to ...


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