Questions tagged [float]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
113 views

PSET 4 - Filter Grayscale

I've managed to make Filter Grayscale work. It wasn't too complicated, I was just missing to cast each color to float as such; void grayscale(int height, int width, RGBTRIPLE image[height][width]) { ...
0
votes
1answer
10 views

float rounds with %2.f

I'm working on pset2 with cash. But something interesting is happening if input is 6.876 and i printf that value of that variable I get 6.88 instead of 6.87. How can I get 6.87 instead of round 6.88? ...
0
votes
4answers
10k views

Problem with pset 1, cash

I get the correct answer for some values, i get the wrong answer for others. I didn't convert my change to cents because I figured I could just keep all my cents, dimes, quarters in decimal values too....
0
votes
1answer
295 views

Readability in C passes tests on instructions page but when submitting, only 2/11 pass

I've written all of my code and tested that the letter, sentence and word output is counting correctly, which it seems to be. I even tested with all of the sentences on the instructions page and that ...
3
votes
1answer
390 views

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

I have written a solution for readability from pset2 but I'm having problems with one of the points: :( handles single sentence with multiple words expected "Grade 7\n", not "Grade 8\n". So I ...
0
votes
1answer
107 views

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?

@app.route("/buy", methods=["GET", "POST"]) @login_required def buy(): """Buy shares of stock""" if request.method == "POST": symbol = request.form.get("symbol") # get stock ...
0
votes
1answer
22 views

Adding a code block to perform operations on float

I am currently on PSET 1 Cash and have my program asking for the amount of change required, not accepting negative values and now I want to add a code block to start performing the operations on my ...
1
vote
1answer
192 views

pset 1 cash get_positive_float not functioning as intended

I wanted to get the positive float using the get_positive_float function, which I declared later. However, it either accepts -0.99999 or rejects 0.999999. The code looks as follows: #include <...
0
votes
1answer
19 views

Why does my program only work on int numbers, not on float ones?

#include <cs50.h> #include <stdio.h> int main(void) { float change, quarter, dime, nickel, penny; int coins; do { change = get_float("Change: "); } while (change < ...
1
vote
2answers
222 views

I can´t get (pset1) greedy/cash.c pennies to work properly!

i´ve been trying to figure out what is wrong with my code for the pset1 cash or greedy program, i know about float imprecision but when i print the last value for "ch" it prints .01000, thus meaning ...
0
votes
1answer
144 views

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

My original code for this problem is as follows: int main(void) { float c = 0; //total coins float $ = get_float("Change: "); while($ <= 0.0099999 && $ >= 0.00000001) { $ = ...
0
votes
1answer
139 views

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

I've wrote the following which passes check50 and operates as intended: #include <stdio.h> #include <cs50.h> #include <math.h> ... int cents = round(change * 100); ... I've ...
0
votes
1answer
49 views

Initialize the variable

I'm wondering why example one of the code doesn't work and example two does. The only change is the repetition of 'float'. The error I get are: unused variable and uninitialized variable. Would just ...
0
votes
1answer
44 views

PSet1 Getting Weird Numbers in Greedy

My code at least appears to similar to others' I have seen on here, but I can't seem to get the right answers. If I enter anything less than "1" I get "0" for the number of coins, and if I enter "1.25"...
0
votes
3answers
512 views

cs50 Problem Set 1: Greedy. float 0.01 problem

sorry for the long title I'm currently doing cs50's problem set 1's Greedy and I've run into an issue. It seems that every cent works except for one's that need to use .01 cent. I've changed my code ...
0
votes
1answer
257 views

pset1 - “greedy” failing at one value

So, I just finished typing my "greedy" code for the fifth time and thought that this time it actually works, but when I run the check it fails at only one value 4.2. I'm going to post my code and hope ...
0
votes
1answer
84 views

Int/Float Conversion

I fail to understand why C outputs a value of 0.000 instead of 0.625. Shouldn't it convert the result of a/b automatically to a float? If I instead write: float a,b; the output is 0.625. Can you tell ...
1
vote
2answers
851 views

Floating Point Imprecision

In Week 2 Lecture (the first one), Mr. Malan says a reason for floating - point imprecision (40:00). I don't get his reason. Sorry for the bad question, but please explain... Thanks in advance.
0
votes
2answers
219 views

Pset1 greedy.c program error

I faced a problem when executing greedy.c. I think every thing is correct (or probably not), but every time I put $4.2 as the input the program outputs 22 coins, which should be 18 ( 16 x 25c + 2 x ...
3
votes
1answer
786 views

pset 1 greedy: how to properly convert float to int

My problem is specifically how to convert the float that the user gives (dollars), into an accurate integer (cents). My code: printf("O hai! How much change is owed?\n"); float change_owed = ...
2
votes
2answers
96 views

Why the printf function is able to print 28 decimal digits, if the float has only 24-bits mantissa?

What is exactly printing in the example in the week 2 lecture: float f = 1.0/10.0; printf("%.28f\n", f); // prints the following: 0.1000000014901161193847656250 I mean, if float is represented on ...
1
vote
1answer
537 views

invalid operands to binary expression

error: invalid operands to binary expression ('char *' and 'double') printf ("Give me a postive number you want change for.\n"); scanf ("%f", &total_float); roundf ("%f" * 100.0 = "%d", &...
1
vote
3answers
102 views

Why floating point comparisons should be avoided?

Why floating point comparisons are inaccurate and should be avoided? For eg. this returns false 2.0 * 5.0 == 10.0 PS : By comparisons I mean equality and inequality, not < and >.