Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int main() {
- FILE *fp;
- fp=fopen("input.txt","w");
- if(fp==NULL) {
- printf("Error!! Opening FIle\n");
- return 1;
- }
- int n, p;
- char s[25];
- printf("Enter The Total Number of Items: \n");
- scanf("%d",&n);
- fprintf(fp, "%d\n", n);
- printf("Enter Item Name & Price: \n");
- for(int i=1;i<=n;++i) {
- scanf("%s %d",s, &p);
- fprintf(fp, "%s %d\n", s,p);
- }
- fclose(fp);
- fp=fopen("input.txt","r");
- int num;
- rewind(fp);
- fscanf(fp, "%d", &num);
- char str[100][20];
- int price[100];
- for(int i=1;i<=num;++i) {
- fscanf(fp, "%s %d",str[i],&price[i]);
- }
- fclose(fp);
- for(int i=1;i<=num;++i) {
- printf("\t\t\t\t\t%d. %s = %d\n", i, str[i], price[i]);
- }
- int quantity[25];
- for(int i=1;i<=num;++i) {
- printf("Enter The Quantity of - %s: ", str[i]);
- scanf("%d",&quantity[i]);
- }
- int total = 0;
- for(int i=1;i<=num;++i) {
- total += price[i] * quantity[i];
- }
- printf("Total: %d\n", total);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement