# Calculator tutorials

This is a discussion on Calculator tutorials within the C Programming forums, part of the General Programming Boards category; Anybody know of any good calculator tutorials for C ?...

1. ## Calculator tutorials

Anybody know of any good calculator tutorials for C ?

2. Originally Posted by Enigmatic
Anybody know of any good calculator tutorials for C ?
It would help if you give us more details. And I think you dont need a calculator tutorial, just c tutorials.
+, -, *, /
First you can start like this:
Define a variable; if the variable is
0, you perform an +
1, you perform a -
2, *
3, /

Code:
```int a,v1, v2;
int result;
while(1){
printf("Enter: 0 for addition, 1 for substraction, 2 for multiply, 3 for divide, 4 to quit!/n");
scanf("%d", &a);
if( a == 4 ) break;
printf("Enter first value:");
scanf("%d", &v1);
printf("Enter second value:");
scanf("%d", &v2);
switch( a ){
case 0:
result = v1 +v2;
break;
case 1:
result = v1 - v2;
break;
case 2:
result = v1 *v2;
break;
case 3:
result = v1 /v2;
break;
default:
printf("Illegal operator/n");
break;
}
printf("result = %d", result);
}```