training

Code I wrote during training
git clone git://git.bitsmanent.org/training
Log | Files | Refs | README

getweekvalue.c (1043B)


      1 /* Esercizio 4.19 */
      2 
      3 #include <stdio.h>
      4 
      5 int main()
      6 {
      7    int productid = 0, quantity;
      8    int prod1 = 0, prod2 = 0, prod3 = 0, prod4 = 0, prod5 = 0; /* product list */
      9 
     10    printf("Product ID: ");
     11    scanf("%d", &productid);
     12 
     13    while(productid != EOF) {
     14       printf("Day's quantity: ");
     15       scanf("%d", &quantity);
     16 
     17       switch(productid) {
     18 	 case 1:
     19 	    prod1 += quantity;
     20 	    break;
     21 	 case 2:
     22 	    prod2 += quantity;
     23 	    break;
     24 	 case 3:
     25 	    prod3 += quantity;
     26 	    break;
     27 	 case 4:
     28 	    prod4 += quantity;
     29 	    break;
     30 	 case 5:
     31 	    prod5 += quantity;
     32 	    break;
     33 
     34 	 /* questi caratteri..
     35 	 case '\n':
     36 	 case '\t':
     37 	 case ' ': 
     38 	    break;
     39 	 ..verranno ignorati. */
     40 
     41 	 default:
     42 	    printf("Il prodotto inserito non è valido!\n");
     43 	    printf("Verificare l'ID e riprovare.\n"); 
     44 	    break;
     45       }
     46       printf("\nProduct ID: ");
     47       scanf("%d", &productid);
     48    }
     49 
     50    printf("Total products price: $%.2f\n", (2.98 * prod1) + (4.50 * prod2) + \
     51 	 (9.98 * prod3) + (4.49 * prod4) + (6.87 * prod5));
     52 
     53    return 0;
     54 } /* E0F main */
     55