Since you are a beginner, I will give you a solution for both of these problems. Yes, a solution. :-) Read the answer for that!
1) First of all,
Exception:
Input string was not in a correct format
Means that the string that you are providing to parse to a decimal, is not in a correct format. Simple english applied and within a fraction of second anyone can understand that the code is complaining about the format. Are you having "," in it? Many other similar problems arise, when you cannot convert the string to a decimal value. If your locale (culture) supports to have 123,45 in a decimal format then make sure you are using the culture that supports such format, and not the default ones. Just asking, this may be a trouble, otherwise debug it to find out more. This MSDN documentation would help you in understanding the decimal formats and how you should consider a decimal value to look like (in string of course):
https://msdn.microsoft.com/en-us/library/dwhawy9k%28v=vs.110%29.aspx[
^]
2) Secondly, the other problem is because you are trying to divide the number by a zero. If you ever studied mathematics (I am not claiming, you never did), you do know that something divided by zero is
undefined. In programming, something divided by zero is "
DivideByZeroException
[
^]". So, you need to make sure you do not divide anything by zero. If you are about to, you can change the flow of program.
int a, b, c;
if(b != 0) {
c = a / b;
} else {
}
This way, you can minimize that error too. Now, I know I didn't provide the solution, but using this general solution you can solve the problem and any problem similar that may arise again.
Now, open Visual Studio, add a breakpoint and
debug the application[
^] to find out what is going wrong and what may be expected or done to make it work fine.