Hi Peliex,
The use of system("PAUSE") is common in windows's console applications and some books suggest to use it, but it is non-portable and useless. For example, if you use Visual Studio to write the code, you can simply go to the project setting > Linker > System and set Subsystem to console. Then, if you run the application with Ctrl+F5, you will see that visual studio automatically add the system("PAUSE") at the end of the application. Any other good IDE provide similar solutions (ofter simpler solutions).
Anyway, it is a console application, so you probably want to launch it directly from a console and, in that case, the console will remain open when the application finish and you will hate that system("PAUSE") at the end of the application.
Note that the use of scanfs for string is considered unsafe. Replace it with
fgets() (with stdin as the file stream).
From an usability point of view, I suggest to move the formula as an argument of the application. For example, if you want to calculate 1 + 2 you do something like this (in the console)
| [xyz] calculate "1 + 2"
Result is 3
|
even if some character can be problematic, I need to think about it.
You can also consider to ask for a particular notation. Since you are new in software development and you probably haven't studied Mathematical logic, you probably do not know that the prefix and suffix notations do not need parentheses. The prefix notation -- lisp use it even if it likes parentheses a lot -- is like this
which is equivalent to
. The suffix notation is the opposite, that is
. This notation is less legible than the other two but it makes possible to implement the calculator very efficiently (it use less memory of the others). It works in this way:
| stack new elements inserted
[] <- 3
[3] <- 7
[3, 7] <- 3
[3, 7, 3] <- -
[3, 4] <- 2
[3, 4, 2] <- /
[3, 2] <- +
[5] <- end of string
[] -> 5
|