Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- struct Recycle
- {
- char name[20];
- float weight, income;
- };
- float get_price(float weight)
- {
- float price;
- if(weight<50)
- price=0.2;
- else if(weight<100)
- price=0.4;
- else
- price=0.6;
- return(price);
- }
- int main()
- {
- struct Recycle person[4];
- FILE *fpointer;
- fpointer=fopen("recycle.txt", "w");
- int count;
- float price;
- for(count=0; count<4; count++)
- {
- fflush(stdin);
- printf("Enter name: ");
- gets(person[count].name);
- printf("Enter material weight: ");
- scanf("%f", &person[count].weight);
- price=get_price(person[count].weight);
- person[count].income=person[count].weight*price;
- price=0;
- fprintf(fpointer, "%s %.2fkg RM %.2f\n", person[count].name, person[count].weight, person[count].income);
- printf("%s %.2fkg RM %.2f\n\n", person[count].name, person[count].weight, person[count].income);
- person[count].weight=0;
- }
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement