0
I want some opnions about my code
My programm is a very basic calculator .Got into programming 2 weeks ago, and im currently doing some basic projects. I went through the Very basics up until pointers. Anny recommendations about my code? Something im doing wrong or could improve It? https://code.sololearn.com/caVxyOdn2Sc3/?ref=app
2 Answers
+ 2
The indentation and code style is a little unusual.
0
I will talk about things you will probably come across later, but I also mention some things for what you should have seen in the lessons.
The first thing I notice, is that you're forward declaring functions inside of functions. I don't think you should be doing that, so adding your menu, sub and sum functions at the top rather than inside functions would make it more readable. Since you're using C you can take advantage of using function pointers for your operations, so you can call something like "operation(int (*func)(num1, num2))" rather than switching, but that's still fine.
I would probably suggest only using one lot of printf's to ask for input, rather than per operation type like you have and you would save a fair few lines of code doing so.
Eventually you will want to add some error handling to make sure you actually get numbers as input. scanf usually returns a number based on how many items it could parse, so you could check if scanf is greater than 0 and that should work.
Other than that, good job for having a go with C. It is quite a nice language to use and very powerful. Remember to have fun and learn everything you can.