Advertisement
win98se

ProgrammingGo - Recycle

Sep 22nd, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. struct Recycle
  4. {
  5.     char name[20];
  6.     float weight, income;
  7. };
  8.  
  9. float get_price(float weight)
  10. {
  11.     float price;
  12.     if(weight<50)
  13.         price=0.2;
  14.     else if(weight<100)
  15.         price=0.4;
  16.     else
  17.         price=0.6;
  18.     return(price);
  19. }
  20.  
  21. int main()
  22. {
  23.     struct Recycle person[4];
  24.     FILE *fpointer;
  25.     fpointer=fopen("recycle.txt", "w");
  26.     int count;
  27.     float price;
  28.  
  29.     for(count=0; count<4; count++)
  30.     {
  31.         fflush(stdin);
  32.         printf("Enter name: ");
  33.         gets(person[count].name);
  34.         printf("Enter material weight: ");
  35.         scanf("%f", &person[count].weight);
  36.  
  37.         price=get_price(person[count].weight);
  38.         person[count].income=person[count].weight*price;
  39.  
  40.         price=0;
  41.  
  42.         fprintf(fpointer, "%s %.2fkg RM %.2f\n", person[count].name, person[count].weight, person[count].income);
  43.         printf("%s %.2fkg RM %.2f\n\n", person[count].name, person[count].weight, person[count].income);
  44.         person[count].weight=0;
  45.     }
  46.     return(0);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement