4
votes
Accepted
pset 1 - cash problem - No errors, am rounding, but still not always correct amount of coins
'while (cent >= 0.25)' here you have accidentally written dollar amount instead of cents.
4
votes
pset1 cash 2022
Looks like you are using the 2022 version of check against the 2021 version of pset1 cash. The 2022 version of the pset has a new function to implement called get_cents. (There may be other ...
3
votes
Accepted
pset1 cash.c guidance
That single ; after your while is an empty statement, and in the code you show it is the loop's body. So your loop keeps doing nothing, and repeat that. Remove that extra semicolon. Semicola are meant ...
3
votes
Accepted
Problem with rounding for pset 1 cash
Try looking at the format specifier you're using to print the number of coins used.
Hint: It shouldn't be %o, that one is used for octal values (base-8).
3
votes
I can´t get (pset1) greedy/cash.c pennies to work properly!
Perhaps you don't understand float imprecision fully enough. If you were to print the value of ch with more digits of precision, you would see what's happening. Try using the following:
printf("%0....
3
votes
Accepted
I can't figure this out can anyone help PLEASE ( line 7 error) cash.c:7:1: error: expected identifier or '(' {
This is a very common newbie problem. The problem lies here:
int main (void);
The semicolon is breaking the code. It must be removed. The correct form is this:
int main (void)
{
//program code......
2
votes
Accepted
pset7 (buy): what does "SELECT cash FROM users WHERE id = 1" do?
It looks like you've implemented it correctly. In the walkthrough, she is using 1 as an example, with the assumptions that it really is user 1 and that the user exists in the database. It also looks ...
2
votes
Accepted
Pset 1 .cash weird expected output
There are two problems with the code.
First, the output does not conform to the program specification. The spec calls for the total number of coins to be printed out and to use specific prompts. ...
2
votes
Accepted
PSet1 Cash returning implicitly declaring library function 'roundf' with type 'float (float)'
Have you read the man page for the function? Maybe there's something your should include in your code that isn't there? ;-)
If this answers your question, please click on the check mark to accept. ...
2
votes
Incorrect output by check50
Your problem might be more logical than with just code. The pset seems to ask more how many quarters, dimes, nickels, and pennies at a minimum can you get to the exact change needed. This requires you ...
2
votes
Accepted
Incorrect output by check50
Time for some tough love. The logic in this code makes no sense. Take this for example:
int q = ((n / 25) % 10);
Say the amount given was $0.75. That makes n = 150. n/25 = 6. 6%10 = 6. But the ...
2
votes
Accepted
HELP, keep getting this error.... error: invalid operands to binary expression ('float' and 'int')
It's a simple problem and the same issue in all cases.
The code is trying to do dollar % 25 BUT, dollar is a float, not an int. The modulo operator requires both operands to be integers. Modulo ...
2
votes
Accepted
CS50 problem set 1 cash
Try printing out the value of cents after each calculation and think about the effect of integer division vs. regular division.
Does the code track BOTH the number of coins for each denomination AND ...
2
votes
Accepted
error: function definition is not allowed here( help!)
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 ...
2
votes
make: *** No rule to make target 'cash'. Stop
You gotta change your directory to where cash.c is located. cd pset1
2
votes
pset1 cash please help I'm stuck
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 ...
2
votes
Accepted
Problem with Pset1 cash 2022
First, the code isn't actually "prompting" the user for anything. Double quotes with nothing between them is not recognized as a prompt. It should ask something like "Please enter the ...
2
votes
PSET 1 CASH stuck!
It looks you have written the body of various functions in the main() itself after function calls. These should go into the respective function definitions, generally places after the closing bracket ...
2
votes
Accepted
CS 50 Pset 1 cash: non-void function does not return a value
You've created 5 functions that each is required to return an int value, yet there's not a single return statement anywhere. That won't get past the cs50 compilers.
The code needs to be changed to ...
1
vote
PSET1 One input doesn't give the appropriate output
Found it.
while (cents - 25 >= 0)
and not
while (cents - 25 > 0)
1
vote
Accepted
(pset1 cash) getting correct answer in terminal output, but check50 shows wrong output
This exercise expects the entire input amount to be converted to coin. It looks like the program will only convert the cents part of the input to coin. The check50 answers are correct. In the first ...
1
vote
Stumped on pset1 cash.c, please help me learn
More accurately, it isn't counting pennies correctly. In fact, it isn't counting a lot of things correctly. (Try $4.20) The cause of the problem is the whole purpose of this pset. Because of that, I'...
1
vote
Accepted
Pset7 Finance - List Index Out of Range Error when accessing users cash
I never found a satisfactory answer to this problem. Suffice it to say that if you receive any error, or make any changes to your SQL database by manually, then you need to close phpliteadmin, close ...
1
vote
Accepted
Pset 1: Cash help
There are serious issues with the way that you're trying to use IF statements. First of all, "n=x" is always true. A single "=" sign is an assignment operator. In other words, it always assigns the ...
1
vote
Accepted
I need help with cash - again
Cut and paste error. What is the value of a dime? A nickel? A penny? I'm sure it isn't 25 cents each!
;-)
When you get to the point that you're not seeing the forest for the trees, as is the ...
1
vote
Accepted
I need help. (pset 1 - cash) I don't get this!
Why does the code increment the amount of change, i, each time it subtracts the value of a coin from it? You should be using a separate variable to track the number of coins.
1
vote
Accepted
I don't understand where I went wrong?
By definition, the function named main does not require a return. From this doc
If the returned type is compatible with int and control reaches the
terminating }, the value returned to the ...
1
vote
Accepted
Transform function into a loop or similar
Its good that you're thinking about how to make the code more efficient. Kudos to you!
Yes, repeating code is a red flag that things can be simplified. But here, the code is very similar but not the ...
1
vote
pset1 Cash: Having a hard time understanding the flow of the app
Simply put, the code is printing the output without calculating the answer.
The code has a nice function called math(), but it is never called by main, so the calculation is never done.
Kudos for ...
1
vote
Problem Set 1, Cash: maths issues
Most important question: did you resave the corrected code and remake it before checking it? The IDE does NOT automatically recompile your code.
I don't think it's an issue with the code above. I ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
cash × 118pset1 × 81
cs50x × 22
cash.c × 13
c × 12
greedy × 12
cs50-pset1 × 7
check50 × 6
error × 6
pset7 × 5
week1 × 4
problem-set-1 × 4
pset × 3
modulo × 3
compile-error × 3
pset2 × 2
finance × 2
variables × 2
cs50x2020 × 2
cs50x2019 × 2
problem × 2
code × 2
float × 2
while-loop × 2
pset6 × 1