Hot answers tagged

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 ...
Blauelf's user avatar
  • 20.9k
2 votes

"cash.c:7:1: error: expected identifier or '('" What do I do?

Get rid of the semicolon on line 6. A semicolon there marks the line as a function signature. You'll learn more about that later.
Cliff B's user avatar
  • 67.4k
2 votes

make: *** No rule to make target 'cash'. Stop

You gotta change your directory to where cash.c is located. cd pset1
Fuelled_By_Coffee's user avatar
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 ...
Cliff B's user avatar
  • 67.4k
1 vote
Accepted

Code not working - cash

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,...
Cliff B's user avatar
  • 67.4k
1 vote
Accepted

CS50 pset 1 cash problem: keep getting 1 as answer

The problem that you're seeing is here: quantity = round (quantity * 100); So, what is the value of quantity before this line execute? What variable actually contains the value of the change to be ...
Cliff B's user avatar
  • 67.4k
1 vote
Accepted

cash CS50 2020 pset1 modulo

Why are you using modulo for this? It produces an unreliable result in this usage. Further, the actual numbers don't make sense. The modulo function returns the remainder after an integer division. ...
Cliff B's user avatar
  • 67.4k
1 vote
Accepted

Why removing a printf function messes up with my code? CS50 pset1 cash greedy challenge

Could it be the missing line break? The output of printf("Your input: $ %.2f", a); printf(", which amounts to %i total.\n", cents); or equivalently printf("Your input: $ %.2f, which amounts to %i ...
Blauelf's user avatar
  • 20.9k
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.
Cliff B's user avatar
  • 67.4k
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 ...
DinoCoderSaurus's user avatar
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 ...
Cliff B's user avatar
  • 67.4k
1 vote
Accepted

PSet1 cash, modulo problem

Welcome to the world of (binary) floating point. A value like 4.2 cannot be precisely represented in binary, it would be represented by an infinite sequence of binary digits. Obviously we don't have ...
Blauelf's user avatar
  • 20.9k
1 vote
Accepted

pset1 cash.c check50 outputs 1 error?

You already understand all the parts of what's happening. Time to put them all together. The round function always rounds at the decimal. It's a simple fix. Move the decimal before you round. Don't ...
Cliff B's user avatar
  • 67.4k
1 vote
Accepted

pset1 cash.c Do While loop executing even when condition = false?

It's doing exactly what it was told. Remember the differences between a while loop and a do/while loop. A while loop can only execute if the condition is true because the test condition is checked ...
Cliff B's user avatar
  • 67.4k
1 vote
Accepted

how to carry over value of int through while loops (cash/less)

You have changed to using cents, but quarter and so on are still in dollars. Variables like count, declared in the function, not globally, are not initialised by default, so start at any value (maybe ...
Blauelf's user avatar
  • 20.9k

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