I am starting and I am learning C and C ++. I am trying to run this code in Visual Studio 2012 Express for Windows Desktop. This is a simple calculator that I wrote myself! But whenever I run it, I get this error Unhandled exception at 0x519600B4 (msvcr110d.dll) in Calculator.exe: 0xC0000005: Access violation writing location 0x00000000.
Forgive me for any mistakes (this is my first time). Thanks!
#include<stdio.h> #include<conio.h> main () { int num1, num2, result; char oper; scanf_s("%d%c%d", &num1, &oper, &num2); switch(oper) { case '+': result = num1 + num2; printf("%d", result); break; case '-': result = num1 - num2; printf("%d", result); break; case '*': result = num1 * num2; printf("%d", result); break; case '/': result = num1 / num2; printf("%d", result); break; default: printf("ERROR: INVALID OR UNRECOGNISED INPUT\n"); break; } _getch(); }
source share