Hot answers tagged

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.
user avatar
  • 361
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).
user avatar
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....
user avatar
  • 63.1k
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......
user avatar
  • 63.1k
3 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 ...
user avatar
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. ...
user avatar
  • 63.1k
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 ...
user avatar
  • 63.1k
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. ...
user avatar
  • 63.1k
2 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 ...
user avatar
  • 20.7k
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 ...
user avatar
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 ...
user avatar
  • 63.1k
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 ...
user avatar
  • 63.1k
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 ...
user avatar
  • 63.1k
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 ...
user avatar
  • 63.1k
2 votes

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

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

Why does this fail one of the tests? (when cash is 4.20)

Recurring theme in this forum, it is a problem of inherent accuracy to the numbers of type fload or double, the machine causes a truncation, rounding in an inadequate way for our purposes such numbers,...
user avatar
  • 5,172
1 vote

Cash-Is my logic correct?

change=round(change*100); So, this line takes the float change, multiplies it by 100 and rounds it to get rid of the problem of how numbers are imperfectly stored in floats, and then stores it back ...
user avatar
  • 63.1k
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 ...
user avatar
  • 63.1k
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 ...
user avatar
  • 63.1k
1 vote
Accepted

Problem with cash, pset1

Three big hints: How many coins in $4.19 ? What happens to the decimal part of a number when you do INTEGER division? When 4.20 is stored as a float, what is actually stored, accurate to 16 digits? ...
user avatar
  • 63.1k
1 vote

Pset1, Cash problem

Just a couple of things, you are assigning an operation between variables of type float to a variable of type int. When this is done the result is truncated, it is not rounded, hence the results you ...
user avatar
  • 5,172
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 ...
user avatar
  • 20.7k
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 ...
user avatar
  • 63.1k
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 ...
user avatar
  • 63.1k
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.
user avatar
  • 63.1k

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