Hot answers tagged

5

Had similar problem with similar message. This is how we found out what was wrong: Executed check50 -h to see what logging options there were. Discovered we can turn on debug logging using --log-level option. Executed check50 --log-level debug path/to/folder.... In the output noticed: fatal: repository 'https:///github.com/me50/$USERNAME' not found. ...


2

The problem is in your nested for loop. It prints a space all the way up until i + j <= n - 1. Once this is no longer true, your program exits the loop. Let's look at this in a little more detail: If n = 7 and i = 0, the if statement in the nested loop will continue printing spaces until i + j > n - 1, meaning when j = 7. As soon as that happens, ...


2

I don't think you saw the video properly. To run c executable files, you should use ./ and the executable file's name. So in this case it is ./hello


2

You gotta change your directory to where cash.c is located. cd pset1


2

It's a simple fix. Functions cannot be placed inside of main. Just move the closing curly brace at the end to just above the line with the following comment: // function gets the minimum number of coins needed; This will close main() properly and allow functions to follow. That should resolve this problem. Not saying there aren't other issues though. If ...


2

The problem is that you're trying to store the float the get_float function gets from the user in a variable that you have initialized as an integer. That's truncating the float to the integer part and discarting the rest. You have to change the data type of that variable to a float. I hope this actually helps you.


1

The proximate reason for 378282246310005 not being identified as Amex is this number > (long) pow(10, 15) is false. Remember pow(10,15) is a 16 digit number. visual compare for the humans 1,000,000,000,000,000 378,282,246,310,005 I would not expect the posted code to loop back to the start; there is no loop in the code.


1

hint: what happens in the code when it reaches the lines of code that say return? hint2: what happens to new_pop, if new_pop is less than end_pop, and new_pop never changes?


1

Sometimes, the compiler can't quite figure out the real problem. But, at least it usually indicates roughly where it is! Look at the line of code: if (sum % 10 ! = 0) The problem lies with the operator " != ". In this code, there's a space between the exclamation point and the equals sign. You can't have a space there. That's what's breaking the ...


1

The structure is simple. Pay attention to placement of curly braces and semicolons, specifically, where they are NOT. #include statements // The next line is a function signature to tell the compiler that // the actual function will follow later. You either need a signature // or the actual function to appear before it is ever used anywhere. // note the ...


1

Strings are immutable. That means that when they are declared, the memory allocated to them cannot be changed. You can put a shorter string in that memory, but not a longer one because it will overwrite other memory allocated elsewhere. When plaintext is declared in the second code snipet, it has exactly one byte allocated to it, to hold the end of string ...


1

it seems that your "mario.c" is in the path: pset1/mario


1

It's the obvious problems that hide in plain sight! ;-) I'll bet it's returning 0 instead. Here's the problem: int func(float val, float input) The function is returning an int, not a float. Because the return type is designated as an int, it's converting the float to int (truncating the fractional part)before returning, and then main is casting it back ...


1

You are already half-way there. Your for loop does something for each iteration. Now, you want to do something inside that loop for each iteration. The answer is another for loop--a concept called "nested loops." The basic structure would be: for(int i = 0; i < n; i++) { //code to execute before the nested loop, if any //the nested loop ...


1

Of course it's moving past the while loop. It's just not doing anything that you see before it terminates. Try inputting a 3 digit number and see what it does. The actual problem is here: if (digits == 13 || digits == 15 || digits == 16) { return digits; } A return statement in main will immediately terminate the program. If it has a value or variable ...


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

You can try replacing whitespaces with a hyphen before saving the entry. By doing this, you save the complete name of the entry and can use it as a url. For this, the search and title rendering will have to modified a bit. While saving the entry use title = title.replace(' ', '-'). A similar approach can be used for searching. For displaying in html, you can ...


1

Once the program has determined if the sum should increase by current_digit or something else, the something else takes a complicated approach. Instead of nesting another loop to work out multi-digit numbers, realize that 'multiply' can only have values in the range of 0 to 18. Consider this simpler code: if (j % 2 != 0) { int multiply = current_digit * ...


1

Your mario.c file is not in your mario directory, but in your pset1 directory. Type mv ../mario.c ../mario into the terminal (or drag and drop the file into the mario folder, if the IDE allows it) and then rerun the make mario command and it should work.


1

Are you using your actual GitHub password or your access token's code? If you have enabled two-factor authentication with GitHub and you haven't created an access token, you will need to create one for CS50 as GitHub no longer allows submit50 to connect using your regular sign-in credentials. You can follow this link to learn how to do this: Creating a ...


1

~First of all when you prompt user why did you typed %s just put like this x = get_float( "change owed") ; ~Second mistake is logical For while loop you just have to divide the rounded number by 25 or 10 or 5 and so on. And then increment the number. Example while( y / 25){ Coins ++ } ; And so on :-)


1

try using /* */ to surround all of your comments instead of the other // prefix. i don’t know why, but my program wouldn’t pass the checks when i used //. it could be something to do with the 2021 upgrades or some issue with clang maybe, i really don’t know but might be worth a shot..


1

you have an error in the following loop: for (d = 7-r; d >= 0; d-) I guess you want to write: for (d = 7-r; d >= 0; d--)


1

The "unpredictible results" is because the variables dQ,mQ etc are not initialized. With input of 2 coins, it's just using whatever happens to be in the memory of the D,N,P variables. Program will eventually get stuck in an infinite loop. If input is .41 (41 cents), program will be stuck here while (dimes <= mQ) because neither dimes not mQ ...


1

The problem is that the code uses do/while loops when it should have used while loops. A do/while loop will ALWAYS run at least once. That means that it will add 4 coins and subtract at least 25 cents, 10 cents, 5 cents and 1 cent no matter what the amount is. If this answers your question, please click on the check mark to accept. Let's keep up on forum ...


1

Curly braces help define scopes (range of allowed operation) for variables and statements in C and some other languages. They also help in defining coding styles. The CS50 course uses a particular style for C programming and style50 check will mark you down if you do not follow the guideline. You can check the guideline on the course website.


1

This is because you've overlooked an important piece of information provided with the explanation of Luhn's algorithm. It actually says in the algorithm to add the products' digits to the checksum and not the product itself(which you've done). Here's an excerpt from the pset1 page for your reference: According to Luhn’s algorithm, you can determine if a ...


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