Addition error?

Hi, so long story short im trying to code a program that takes in user inputted data about percentages and using it to later on calculate a final grade. 4 percents are inputted, for Assignments, Midterm1, Midterm2, and Finals. If the percents dont add up to 1 (i tell the user to enter the decimal value) I set up and if statement to catch it and end the program. Except that if i type in

Assignments = .3
Midterm1 = .3
Midterm2 = .3
Finals = .1

the program doesn't recognize that they add up to 1. Heres the relevant portion of my code
http://i709.photobucket.com/albums/ww94/funnygirl212/Programming%20Help/ProblemCode.png

Here's some examples of how it works
1)http://i709.photobucket.com/albums/ww94/funnygirl212/Programming%20Help/PRoblem.png
2)http://i709.photobucket.com/albums/ww94/funnygirl212/Programming%20Help/ProblemEx2.png

And heres what i dont understand
1)http://s709.photobucket.com/user/funnygirl212/media/Programming%20Help/ProblemWHY-1.png.html?sort=3&o=1
2)http://s709.photobucket.com/user/funnygirl212/media/Programming%20Help/ProblemEx1-1.png.html?sort=3&o=2

Why is it saying .3 + .3 + .3 + .1 != 1 when .1 + .3 + .3 + .3 == 1?
How about posting the actual code, in your post, inside code tags, so we can copy, compile and run your program if we so desire.

Do you realize that floating point numbers are approximations and not all decimal values can be held accurately?

Have you tried printing each of the entered values to see what the computer actually thinks they are?

Topic archived. No new replies allowed.