Hello everybody, i make a simple calculator with C. When I compile it, the compiler didn't show error but when I run my program the result is wrong...
This is my code:
////////////////////////////////////////////////
// Calculator //
// Crated by : Invecta //
// Thanks to all members of komunitas-bsi.com //
////////////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
int main(){
int i, n, iNumber, iResult, iChoice;
printf("+----------------+\n");
printf("| Calculator |\n");
printf("+----------------+\n");
printf("| 1. + |\n");
printf("| 2. - |\n");
printf("| 3. * |\n");
printf("| 4. / |\n");
printf("+----------------+\n");
printf(" Select your choice : ");
scanf("%d",&iChoice);
switch(iChoice){
case 1:
system("CLS");
printf("Data : ");scanf("%d", &n);
for (i=1; i<=n; i++){
printf("Number %d : ", i ); scanf("%d",&iNumber);
iResult+=iNumber;}
break;
case 2:
system("CLS");
printf("Data : ");scanf("%d", &n);
for (i=1; i<=n; i++){
printf("Number %d : ", i ); scanf("%d",&iNumber);
iResult-=iNumber;}
break;
case 3:
system("CLS");
printf("Data : ");scanf("%d", &n);
for (i=1; i<=n; i++){
printf("Number %d : ", i ); scanf("%d",&iNumber);
iResult*=iNumber;}
break;
case 4:
system("CLS");
printf("Data : ");scanf("%d", &n);
for (i=1; i<=n; i++){
printf("Number %d : ", i ); scanf("%d",&iNumber);
iResult/=iNumber;}
break;
}
printf("The result is %d\n", iResult);
system("PAUSE");
return 0;
}