Я не могу получить общую стоимость в этой программе...
#include <stdio.h> #include <stdlib.h> typedef struct booklist { char title[30]; char author[30]; int cost; }booklist; int main() { booklist *b; int n,i,t=0; printf("Enter the number of books: "); scanf("%d",&n); b=(booklist*)malloc(n*sizeof(int)); printf("Enter the records for %d books\n",n); for(i=0;i<n;i++) { printf("\nBook %d= ",i+1); printf("\nEnter the title "); scanf("%s",(b+i)->title); printf("\nEnter the author of the book "); scanf("%s",(b+i)->author); printf("\nEnter the cost of the book "); scanf("%d",&(b+i)->cost); } printf("\n The detailed record is \n"); printf("\n Title Author Cost \n"); printf("-------------------------"); for(i=0;i<n;i++) { printf("\n %s %s %d \n",(b+i)->title,(b+i)->author,(b+i)->cost); } for(i=0;i<n;i++) { t=((b+i)->cost)+((b+i)->cost); } printf("Grand total cost is %d\n",t); return 0; }
Что я уже пробовал:
Я пытаюсь получить общую стоимость ..