|
| crodino911 (7) | | ||
Just try it and let me know what you think!
| |||
| Bazzy (2946) | | ||||||||
while or a do-while is bettersystem("pause"); read http://www.cplusplus.com/forum/articles/7312/
There is no input validation: http://www.cplusplus.com/forum/articles/6046/
| |||||||||
Last edited on | |||||||||
| crodino911 (7) | |
| Thank you for all your precious advices. 'a' is before LOOP: because you don't need to reinsert that value since in evrey function (if-else) n(the result of the operation)=a. So you can do 2 + 3 = 5 here you type the next operation for example * wich is 'b' 2 wich is c = 10 wich is d. and so on. As you can see the result takes itself the place of 'a', that's why LOOP: is after 'a'. Any other advice or consideration? | |
| crodino911 (7) | | ||
I just made some changes, i think it a lot more user-friendly now:
I changed the structure of the function as you suggested me; there is no need to press '=' after every operation; you can type the whole calculation in one line and get a less "ugly" output like this: 2+4+5*2/2 (press enter and not '=') 2+4=6; 6+5=11; 11*2=22: 22/2=11; Looks better? | |||
| kbw (1032) | |
goto LOOP? Very naughty.There an example of a calulator in the 1st edition of Stroustup's The C++ Programming Language that uses recursive decent. | |
| kbw (1032) | |
| See chapter 6 in the current (3rd) edition. | |
| Bazzy (2946) | |
| The code of that is here: http://www.research.att.com/~bs/dc_command_line.c | |
| crodino911 (7) | |
| It is quite difficult for me to fully understand the whole code since i started programming in c++ from less than a week. However i don't understand what's the problem with using the goto statement(i apologize for the noob question). | |
| Bazzy (2946) | |
| Read this: http://en.wikipedia.org/wiki/Goto#Criticism_of_goto_usage | |
| crodino911 (7) | |
| Alright, i got it.However i'm trying to use a while or do-while instead of the goto statement but i just can't figure out how to do it whithout massive modification of the code.Any idea? | |
| kbw (1032) | |
| The code is quite a leap to begin with, but if you have an interactive environment like Visual Studio or XCode, you can step thru the program one line at a time. You'll learn quite a lot from it. The calculator allows to you make simple variable assignements (as in BASIC) and go on to use them in further operations. It's pretty cool. | |
| crodino911 (7) | |
| Thank you, i'm looking at that right now and i find it really useful!I didn't know it existed even!By the way, what calculator are you talking about?Mine or the one posted in the link? | |
| kbw (1032) | |
| Stroustup's version. The book will have some useful commentary. | |
| Bazzy (2946) | | |
If you want to add a do-while loop in your code, you don't have to change much things: replace LOOP: with do{and goto LOOP; with }while(true); | ||
Last edited on | ||
| crodino911 (7) | |
| Thank you very much, it was right in front of me and i just couldn't see it! | |
This topic is archived - New replies not allowed.

