learning-cc4e

Solution to https://cc4e.com/. If you copy these you're not right in the head.
git clone https://kaka.farm/~git/learning-cc4e
Log | Files | Refs

solution.c (692B)


      1 #include <stdio.h>
      2 
      3 int main()
      4 {
      5   char line[256];
      6   char opcode;
      7   float value, display = 0.0;
      8 
      9   while(fgets(line, 256, stdin) != NULL) {
     10     /* Use sscanf to parse data from a string. */
     11     sscanf(line, "%c %f", &opcode, &value);
     12     if ( opcode == 'S' ) {
     13       break;
     14     } else if ( opcode == '=' ) {
     15       display = value;
     16     } else if ( opcode == '+' ) {
     17       display += value;
     18     } else if ( opcode == '-' ) {
     19       display -= value;
     20     } else if ( opcode == '*' ) {
     21       display *= value;
     22     } else if ( opcode == '/' ) {
     23       display /= value;
     24     } else {
     25       printf("Bad operation: %c\n", opcode);
     26       return(-1);
     27     }
     28 
     29     printf("Display: %.2f\n", display);
     30   }
     31 }