albertibay 0 Report post Posted January 12, 2013 (edited) um here is the whole script i just don't understand whats wrong 1+1+1+1 divided by 4. VB Keeps on insisting its 3.25 Even with a direct approach it fails Edited January 12, 2013 by albertibay Share this post Link to post Share on other sites
diagostimo 11 Report post Posted January 13, 2013 what you need to do is bracket your equation like so: (1 + 1 + 1 + 1) / 4 as when you don't bracket it it adds the values together plus the last value divided by 4, so your essentially doing this: 1 + 1 + 1 + 0.25 but if you bracket it, what's inside the brackets is one value, in this case 4, then you divide that calculated value by 4 returning 1, just remember that brackets are very important when calculating in programming, as the program takes the calculation very literal, also separating your equation into brackets even when not needed sometimes makes it easier to understand what's going on Share this post Link to post Share on other sites
dolarmak 23 Report post Posted January 13, 2013 this is the same problem people have with math regularly. You have to remember that Division and Multiplication comes before Addition and Subtraction so if you don't use brackets it does them first. Computer programs do that literally like Diag said. Share this post Link to post Share on other sites
RageMage 5 Report post Posted January 13, 2013 Order of operations is very important when dealing with something like this. Brackets work in this case though it's not the best programming practice in my opinion. I'd say the total from the 4 text boxes should be stored into a local variable named something like, gradeTotal, and then use that variable to find the average, this has 2 benefits, the first being that it's easier to keep from making a simple mistake like that, the other is if you wanted to do more with the total it would much simpler to work with 1 variable than 4 values each time you wanted to make a call to the total. Just as an example if you were doing a receipt program that took a list of values then found the subtotal, the sales tax, the total calculated change. Since the total is really being used once here though it really is moot point which method is used in this case though expanding on the program would warrant the necessity of variables On a kinda off topic note, I'm surprised Basic is still being used. I guess it isn't all that unbelievable since it hasn't been that long since I last used basic, only 15 years ago. Share this post Link to post Share on other sites
albertibay 0 Report post Posted January 14, 2013 thanks for the help how could i have forgotten basic math Share this post Link to post Share on other sites