# Tag Info

Accepted

### pset1 - "greedy" failing at one value

This is a very common problem and the whole point of greedy.c, so let me try and give the definitive answer. Float values with a decimal part (to the right of the decimal, in case you weren't certain)...
• 69.2k
Accepted

### Pset2 - Readability: How to round a .5 number depending on the 2nd digit after the decimal point

Your problem isn't that round(7.535600) rounds to 8 (It should, and does), but that 7.535600 isn't the correct index value. For that text, I'd expect these values: 96 letter(s) 23 word(s) 1 sentence(...
• 18.7k

### 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....
• 69.2k
Accepted

### Pset1 Cash - Trying to round float value DURING computation and not after

The code seems far more complicated than necessary, but this seems to be because you're trying to handle the imprecise float storage problem unsuccessfully. This can be resolved by simply converting ...
• 69.2k
Accepted

### cs50 Problem Set 1: Greedy. float 0.01 problem

Most of the problem is that no matter what you do, you keep putting the result back into change, a float. Floats have this nasty little problem that they don't store fractional parts of a number, the ...
• 69.2k
1 vote
Accepted

### Convert comma to point in a Float (C)

This is all about that comma. You're trying to get a decimal number from the user. That means that you have to enter a period, not a comma. The C language recognizes a sequence of digits with a single ...
• 69.2k
1 vote
Accepted

### PSET 4 - Filter Grayscale

The reason is that if the code is doing division with all integers, it will do integer division, not normal division. Integer division will truncate the fractional part of the division. So, if the ...
• 69.2k
1 vote
Accepted

### float rounds with %2.f

I know of two ways, but neither can be done through how printf works. The way I would do it would be to multiply the value by 100 and cast it to an int, which would cut off any remaining decimal ...
• 1,924
1 vote

### In the buy function the variable float(stock_total) will not convert to float. Can someone explain how to fix it? Also what is causing the problem?

The value being coerced has mixed character data (the \$ in the case of \$208.43). Consider either sanitising the return value or revising the finance.db data type.
1 vote
Accepted

### Adding a code block to perform operations on float

So you decided to make some functions, why not. The function definition would be like return_type function_name(param1_type param1_name, param2_type param2_name, ...) { // body of the function } ...
• 21k
1 vote
Accepted

### pset 1 cash get_positive_float not functioning as intended

I declared n as an int, not a float. That caused the problem.
• 31
1 vote
Accepted

### Could someone explain the significance of double round in pset1 "greedy" (less comfortable)?

double is one of the types in C, like int and char. It's a double-precision floating point number. So #include <math.h> double round(double x); means that the function takes a double and ...
• 18.7k
1 vote
Accepted

### Initialize the variable

It's pretty straightforward. In the second one, the code uses a single variable called c. No problems. In the first one, by including float in the while statement, the code is redeclaring the ...
• 69.2k

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