Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int main() {
- FILE *fp;
- if((fp=fopen("input.txt","r"))==NULL) {
- printf("Error!! Opening FIle\n");
- return 1;
- }
- int num;
- fscanf(fp, "%d", &num);
- char str[25][20];
- int price[25];
- 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