while loop with || wont work

Hey! I'm working on a practice program and i ran into a problem! I've looked around , and i'm pretty sure that this should work, but i really can't figure out why it doesn't!

1
2
3
4
5
6
7
8
9
10
while (total != 3.50){
		if (total < 3.50){
			cout << "Insert coin: ";
			cin >> inserted; //inserted is a double
			while ((inserted != 1.00) || (inserted != 0.25)){
				cout << "Please insert correct denominations: "; 
				cin >> inserted;
			}//Even if I insert 1.00 or 0.25, the loop keeps on going
			total += inserted;
		}


I really appreciate any help!
Floating point values are inherently inexact:
http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
Thanks for the article! It looks like an informative read!
But quick question, doesn't that mean that the first while loop
while (total != 3.50) // total is a double as well
shouldn't work either?
Last edited on
The condition in the loop

1
2
3
4
while ((inserted != 1.00) || (inserted != 0.25)){
	cout << "Please insert correct denominations: "; 
	cin >> inserted;
}//Even if I insert 1.00 or 0.25, the loop keeps on going 


shall be rewritten the following way

((inserted != 1.00) && (inserted != 0.25)){
It works now! Thank you very much! But if you don't mind me asking, I get how it works kind of, but isn't the logic behind && that if one statement is true and the other is false, it returns false? So if i put 0.25, that means that the first statement is false, but the second is true. Shouldn't that return false with an and?
Topic archived. No new replies allowed.