Not Checking if Greater than 0
Hello sirs and ma'ams, today i have run into a problem. I have a bit of code, that should check if a variable "dismoney" minus a variable "cost" is >= zero.
if (dismoney - cost >= 0)
actualQuantity = actualQuantity + quantity;
print (actualQuantity);
dismoney = dismoney - cost;
print (dismoney);
When I print actualQuantity and dismoney, actualQuantity is increased by quantity. Good. Dismoney is decreased by cost. Good. When this bit of code repeats, eventually, dismoney - cost will be < zero. Okay. Currently, cost is 10 and dismoney is 18. After 1 time, it should stop running. However, it continues to subtract, far into negatives and presumably, to no end. Full gratitude towards any/all answers :).
Answer by EmHuynh · Feb 16, 2016 at 06:50 AM
Hey, @UnityAlexV. The if statement is missing its set of curly brackets. Here you go:
if (dismoney - cost >= 0) {
actualQuantity = actualQuantity + quantity;
print (actualQuantity);
dismoney = dismoney - cost;
print (dismoney);
}
Thank you, sir! $$anonymous$$uch obliged. That's twice you've helped me, if I'm not mistaken!
Your answer
Follow this Question
Related Questions
C# Greater Than or Equal To 1 Answer
Is it possible to use . Operator to access variables in classes in lists 1 Answer
Subtracting a time difference from an int? 1 Answer
And/Or Operator C# 2 Answers
float subtraction gives wild answers? 2 Answers