I am taking a course in C programming at school, I'm still new to programming. I was wondering if there was a simpler way of programming what I have now. Or just a better way in general.
And can you sight any mistakes I might have made or might cause a bad habit in the future?
Code:
/*Basic Calculator, using two numbers, choosing from four different
choices, with a basic fail catch only at choice selection.*/
#include <stdio.h>
int main(void)
{
int sum,diff,pro,quo,choice,A[1]={0},S[1]={0},M[1]={0},D[1]={0};
printf("[1] Addition\n[2] Subtraction\n[3] Multiplication\n[4] Division\n");
scanf("%d", &choice);
switch(choice)
{
case 1:
printf("Finding the sum, enter two numbers: \n");
scanf("%d %d", &A[0], &A[1]);
sum=A[0]+A[1];
printf("The sum of %d and %d is %d\n", A[0], A[1], sum);
break;
case 2:
printf("Finding the difference, enter two numbers: \n");
scanf("%d %d", &S[0], &S[1]);
diff=S[0]-S[1];
printf("The difference of %d and %d is %d\n", S[0], S[1], diff);
break;
case 3:
printf("Finding the product, enter two numbers: \n");
scanf("%d %d", &M[0], &M[1]);
pro=M[0]*M[1];
printf("The product of %d and %d is %d\n", M[0], M[1], pro);
break;
case 4:
printf("Finding the quotient, enter two numbers: \n");
scanf("%d %d", &D[0], &D[1]);
quo=D[0]/D[1];
printf("The quotient of %d and %d is %d\n", D[0], D[1], quo);
break;
default:
printf("Choice not listed!");
break;
}
return 0;
}