5

You have the right idea behind how the code works, it's just your English to C needs some practice (understandably). int main(void); This is, as its name suggests, the "main" method. Essentially, when you say to run the program, it looks for main(void) and goes from there. Therefore, all your other code should be inside this function, Which will take care ...


5

this is an example on a program with multiple source code files. C allows you to call a function that is defined in one file from another. we do that all the time (e.g., when we call printf, obviously it's not defined in our source code file). to make use of that, all you need to do is to compile your source code files and link the object files together to ...


4

Common problem. The compiler looks at all the possible paths through the code and checks to see that there is going to be a guaranteed, unconditional return to satisfy the need for a return value. But, compilers are dumb. They don't recognize that you can create a fully conditional path that must hit a return. In your case, the fix is simple. The final else ...


4

It looks like the three errors are on lines that call binarySearch(...). The issue is with the array parameter in the call. When you define the function (when you write the prototype) you need to show that something is an array with the form type name[], like you did with int array[]. However, when you call the function, you want to pass the entire ...


3

The types char, short, int, long int, and long long int are often referred to as integer types. Per its manual, the function atoi takes a value of type const char *. I assume your variable named k is of type char [] or char * in which case k[step] would actually be of type char. There is no implicit conversion of an integer type to a pointer type and that ...


3

In C all variable names have to be declared before they are used. If you try to use the name of a variable or a function that hasn't been declared you will get an "undeclared identifier" error. You issue deals with scoping. To fix your issue you need to declare the variable height before the while lope. Your code should be the following: int height; do {...


3

It's because you did a calculation and didn't do anything with it. You have cents - 25; Where are you putting the result? All of these would work: int change = cents - 25; cents = cents - 25; cents -= 25; The infinite loop is another story. To fix that loop, you'd use either of the latter two. If this answers your question, please accept this answer to ...


3

It's mostly a duplicate, but it bears repeating and could use a more specific answer here. Your logic is right in that, assuming there are no issues with the data fed to it, the function will return a bool one way or another. The problem is that the compiler isn't smart enough to recognize the complexity of the logic. So, the compiler looks at the ...


3

Simple fix. Look at the line: int letter = 'plaintext[i]' ; You are trying to put the integer (ASCII) value of a letter stored at plaintext[i] into the variable letter. The idea is right, but look at what you did. int letter = 'something' ; When you use the single quotes around something, it has to be a single character. If you had used double quotes, ...


2

Consider following question: what happens, if there is no value in values[]? In such case, assuming n is greater than 0, we would never reach any of the return statements: First one wouldn't get executed because of the condition: if(values[i] == value) which is never true in our case. Second one also wouldn't get executed, since n doesn't change its ...


2

:( greedy.c compiles \ expected an exit code of 0, not standard error of "greedy.c:7:4: error: expected identifie..." That frown :( and the fact that it is displayed in red means that your code didn't pass the compile "test". You then have all those yellow messages with a :| which means those tests never ran. Check50 shows you all the tests and color ...


2

Happy to help. You're running into syntax errors, which you'll have a lot of as you're getting started. Always best to cure them in order because sometimes the early ones cause a lot of later ones. I think the reason you're not finding the first one is that it's one of those deceptive ones where the problem isn't on the line where it's being signaled. ...


2

Make sure the file named adder has the extension .c. Also make sure you're executing this command make adder NOT make adder.c


2

You are seeing lots of very strange errors because the compiler is having a hard time understanding the code. The compiler takes things very literally, and if the syntax is not 100% perfect, the compiler will be unable to complete it's job. Syntax is the rules that your code needs to adhere to to be understandable to the compiler. This includes things like ...


2

for (int i = 0; i < candidate_count; i++) { if (candidates[i].votes >= maxvote) { maxvote = candidates[i].votes; winner = candidates[i].name; printf("The winner is %s\n", winner); } } the logic of your code to get the max number of votes is correct, but your logic to get the winner is a ...


1

The function signature has changed. From the CS50 Programmer's Manual char *get_string (const char *format, ...); DESCRIPTION Prompts user for a line of text from standard input and returns it as a string (char *), sans trailing line ending. Supports CR (\r), LF (\n), and CRLF (\r\n) as line endings. Stores string on heap, but library’s ...


1

You're right. The compiler just knows that there's a possibility of getting to the end of the code without seeing a return statement, so it's unhappy. However, your fix in the comments has a flaw. What happens when a non-alpha is passed to this function? It will return a bad value because it will be treated as a lower case letter. Instead, you could have ...


1

Compiler does not complain about missing cs50.h, so that looks right. The linker does complain, though, and that's probably because you did not pass -lcs50 when compiling (telling the linker to consider cs50 library). make likely pulls that list from the LDLIBS environment variable, so you can add it there, or create a makefile mentioning that lib.


1

int key = atoi("argv[1]"); this is using the literal string "argv[1]", not the value stored in argv[1]. Also, you should be checking that argv[1] exists before you use it as an argument to atoi (ie, check that argc == 2 first).


1

Actually, no, you're not using argv[1]. int key = atoi("argv[1]"); By putting it in double quotes like that, you're telling the code to use the literal string "argv[1]" instead of the var. It amounts to doing this: int key = atoi("fuzzy kitten"); By surrounding anything in double quotes, it means to use exactly what is in quotes as a literal ...


1

There are a few simple issues. First, octave is being declared and then redeclared, but, amusingly, that isn't the actual problem. The real problem is that they are being declared inside of code blocks attached to the if/else statements. That means that after the closing curly brace after each declaration, they go out of scope and cease to exist! You ...


1

check50 for fifteen replaces the draw function with a simple one whose output is then used for the tests. If your own draw function contains code (setting the values of global variables or calling other functions, for example) that would prevent fifteen.c from compiling, you'll see this issue. The spec will be updated soon to make it clearer that your draw ...


1

no function main () in helpers, hence the error when compiling, you only have to type make in the terminal, if you are located in the appropriate directory, by the way the swap function will not work, see passing parameters to a function by values or by reference. For more information you can see the link https://cs50.stackexchange.com/questions/10145/why-...


1

The root of this problem lies in the order of operations. In C, postfix increment (++) binds more tightly than dereference (*). Thus, what the code *coins++; does is not to dereference coins and then increment the stored value; rather, it increments the pointer coins and then dereferences this new pointer. The compiler is complaining of the fact that the ...


1

The variable a is declared as a single integer. In the line if (a > a[y+1]) this code attempts to compare a to an array of the same variable name. This presents two problems. First, two vars can't have the same name in C. Second, nowhere in the code is an array declared. So, this will never compile. I looked at the code on that link. It's unfortunate ...


1

Hopefully, this article from Cloud9 support, Code Disappeared or Lost, will help you recover your source code.


1

to understand what causes the error, you need to understand three things: the difference between defining a variable and using it. scoping. shadowing. first off, when you use a variable that was previously defined in your code, you don't mention the type again. int x; // define x to be of type int x = 10; // use x (in this case, set it to 10) second, ...


1

atoi() transforms a string into a number, not a char. As it expects a char* it is telling you to put the & so that it can work with an address. Also, to fill an int array, try the following: int k[LENGTH]; for (int i = 0; i < LENGTH; i++) { k[i] = number; } TL; DR: You put in a parameter of the wrong type.


1

That's GetInt(), not getint(). C is case sensitive.


1

Your problem now is that you have written ; after int main (void). Delete ; and everything should be right. Your main function should be: int main(void) { int (n); int n = GetInt(); do { n = GetInt(); } while (n < 0 && n > 23); for (int i = 0; i < n; i++) { printf("##") } }


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