Thread: Calculator tutorials

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    13

    Calculator tutorials

    Anybody know of any good calculator tutorials for C ?

  2. #2
    Registered User Afrinux's Avatar
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    46
    Quote 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);
    }

Popular pages Recent additions subscribe to a feed