Advertisement
Sergio923

Untitled

Apr 21st, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.29 KB | None | 0 0
  1. #include <stdio.h>
  2. #define SIZE 3
  3.  
  4. float funCosto (int ar[], size_t j);
  5. float total(int ar[], size_t t);
  6.  
  7. int main (void){
  8.   int hours[SIZE]={0};
  9.   int i,car, x=0;
  10.  
  11.     printf("Inserire le ore di giacenza:\n");
  12.  
  13.       for(i=0; i < SIZE; i++){    /*inserisce i valori*/
  14.       scanf ("%d", &hours[i]);
  15.       }
  16.           /*stampa la tabella dei valori*/
  17.           printf ("Car\t  Hours\t  Charge\n");
  18.           for (car = 0; car < SIZE; car++){
  19.             printf("%d\t  %d\t  $%.2f\n", car, hours[car], funCosto(hours, car));
  20.           }
  21.          
  22.          
  23.             puts("");
  24.             printf("Il totale è:  %.2f\n", total(hours, x));  
  25.  
  26. }
  27.  
  28.  
  29. float funCosto (int ar[], size_t j){ /*prototipo di funzione*/
  30.   float tot;                          /*calcola le ore in denaro*/
  31.                                           /*nei vari casi*/
  32.      if (ar[j]<=3){
  33.       tot = 2;
  34.      }
  35.       else if(ar[j]>3 && ar[j]<24){
  36.         tot= (((ar[j]-3)*0.50)+2);
  37.       }
  38.        else if(ar[j]==24){
  39.         tot=10;
  40.        }
  41.        else{
  42.         tot=-1;
  43.        }
  44.        return tot;
  45.   }
  46.  
  47.   /*calcola il totale*/
  48. float total(int ar[], size_t t){ /*prototipo di funzione*/
  49.  
  50.   float sum=0;
  51.    
  52.     for (t=0; t< SIZE; t++){
  53.       sum += funCosto(ar,t);
  54.     }
  55.     return sum;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement