\* C program using structure Calculate party expenses *\
# include < stdio.h >
# include < conio.h >
typedef struct item_details
{
char itemName[30] ;
int quantity ;
float price ;
float totalAmount ;
} item ;
int main( )
{
item thing[MAX] ;
int i, choice ;
int count = 0 ;
float expenses = 0.0f ;
i = 0 ;
do
{
printf("\n Enter item details [%2d]:\n", i+1 ) ;
printf(" Item Name : ") ;
fgets(thing[i].itemName, 30, stdin ) ;
printf(" Item Price : ") ;
scanf("%f",&thing[i].price ) ;
printf(" Item Quantity : " ) ;
scanf("%d",&thing[i].quantity ) ;
thing[i].totalAmount=(float)thing[i].quantity*thing[i].price ;
expenses += thing[i].totalAmount ;
i++ ;
count++ ;
printf("\n Want to add more items press 1 (for exit press any key): ") ;
scanf("%d",&choice ) ;
getchar() ;
}while(choice == 1) ;
printf(" All details are:\n") ;
for(i=0; i< count; i++ )
{
printf("%-30s \t %.2f \t %3d \t %.2f\n\n",thing[i].itemName, thing[i].price, thing[i].quantity, thing[i].totalAmount ) ;
}
printf("#### Total expense: %.2f\n",expenses);
printf(" Want to divide in friends (press 1 for yes) : ") ;
scanf("%d",&choice) ;
if( choice == 1 )
{
printf(" How many friends? ") ;
scanf("%d",&i ) ;
printf(" Each friend will have to pay: %.2f\n",(expenses/(float)i) ) ;
}
printf(" ~Thanks for using me... Enjoy your party!!!~\n" ) ;
return 0 ;
}