Skip to main content

Questions tagged [float]

The tag has no usage guidance.

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

Convert comma to point in a Float (C)

I wrote a code that I'm studying where the idea would be to show the change for a certain purchase, however, in the field where the customer enters the price, if I enter, for example: 9,50 instead of ...
Nathan's user avatar
  • 3
0 votes
1 answer
69 views

How to get accurate float average of numbers

I'm in Lecture 2 on Arrays, and I am playing with the example Professor Malan gave about taking a user's input for the number of test scores, as well as for the scores themselves, and outputting the ...
Joseph J Filoramo's user avatar
0 votes
1 answer
741 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]) { ...
highpointer's user avatar
0 votes
1 answer
79 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? ...
arianwww's user avatar
0 votes
1 answer
445 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 ...
JackJack's user avatar
3 votes
1 answer
707 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 ...
Ada's user avatar
  • 35
0 votes
1 answer
149 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 ...
grggthwrth's user avatar
0 votes
1 answer
24 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 ...
Andrew Alton's user avatar
1 vote
1 answer
235 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 <...
O1G's user avatar
  • 31
0 votes
1 answer
21 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 < ...
WheySkills's user avatar
1 vote
2 answers
247 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 ...
ikanimai's user avatar
0 votes
1 answer
152 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) { $ = ...
alienanteater's user avatar
0 votes
1 answer
155 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 ...
AvidUrner's user avatar
0 votes
1 answer
63 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 ...
Knovolt's user avatar
0 votes
1 answer
46 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"...
Alex Durante's user avatar
0 votes
1 answer
261 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 ...
PetarNPetrov's user avatar
0 votes
3 answers
592 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 ...
Domas Kalinauskas's user avatar
0 votes
1 answer
173 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 ...
Alberto's user avatar
  • 21
1 vote
2 answers
3k 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.
sophiemath's user avatar
3 votes
1 answer
803 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 = ...
andydavies's user avatar
2 votes
2 answers
116 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 ...
Marek Paralič's user avatar
1 vote
1 answer
614 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", &...
Mo1's user avatar
  • 142
0 votes
2 answers
230 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 ...
XT Tony's user avatar
1 vote
3 answers
150 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 >.
Sammy Jiang's user avatar