This is for my assignment for a course, and I was wondering what is wrong with my variable total? Whenever I enter a order number, it saids total is being used without being defined. I already did
When a variable is defined without being initialized(assigned a value), it holds the value that was previously in the spot of memory it is now located. If you do not assign total a value when it is defined, it is not automatically set to zero.
That is why when you try to execute:
total = total + 2.19;
you are having issues. Because at that point, total does not equal anything, usable anyway. Try:
first error void main() this is NOT the c++ standard and some compilers will even reject this.
second errordouble total; total is a piece of memory in your RAM and could be anything from part of a picture to that video you were just watching, it has just been declared as a double. so when you do total = total + 2.19;you are really doing [yourpicture] += 2.19; which will give you some random value. setting it to 0 when you declare it will fix your problem with that. double total = 0;
also all the else if statements should be written into a switch statement.