IAN L.
TAREGA BSIT-1B
#include <stdio.h>
#include<string.h>
#include <stdlib.h>
#include <conio.h>
typedef struct Items{
char name[20];
int qty;
float price;
}item;
int main()
float total = 0, sum = 0,t_payment = 0,friends_money,friends_change=0;
float sum_cash = 0,gen_change = 0,cash;
int i,j,friends, temp;
char choice,choice2;
item list[10];
for(i = 0; i <= temp; i++)
printf("Enter Item Details %d\n", i+1);
printf("Item: ");
scanf("%s", list[i].name);
printf("Quantity: ");
scanf("%d", &list[i].qty);
printf("Price: ");
scanf("%f", &list[i].price);
printf("\n");
printf("Do you want to add another? (Y / N): ");
scanf("%s",&choice);
if(choice == 'y'|| choice == 'Y'){
temp++;
}else{
break;
int cnt = i;
printf("\nALL ITEM DETAILS:\n");
printf("ITEM | QUANTITY | PRICE \t | TOTAL ");
for(i = 0; i<=cnt; i++){
printf("\n%s\t%12d\t%27.2f\t%26.2f",list[i].name, list[i].qty, list[i].price, sum = (float)list[i].qty *
list[i].price);
total+=sum;
printf("\n");
printf("\n\nTotal Payment: %.2f\n",total);
printf("\n");
printf("Do you want to divide the expenses? (Y / N): ");
scanf("%s",&choice2);
printf("\n");
if(choice2=='Y'||choice2=='y')
printf("Enter total number of friends: ");
scanf("%d",&friends);
printf("Total payment for each friend: %.2f",t_payment=total/friends);
printf("\n");
else if(choice2=='N'||choice2=='n')
printf("Enter Cash: ");
scanf("%f",&cash);
while(cash<total)
printf("\nInvalid Cash");
printf("\nEnter cash again: ");
scanf("%f",&cash);
float solo_change=cash-total;
printf("\nTotal Cash Received: %.2f",cash);
printf("\nThe general Change: %.2f",solo_change);
exit(1);
else
while(choice2)
printf("Invalid input\n");
printf("Do you want to divide the expenses? (Y / N): ");
scanf("%s",&choice2);
printf("\n");
if(choice2=='N'||choice2=='n')
printf("Enter Cash: ");
scanf("%f",&cash);
while(cash<total)
printf("\nInvalid Cash");
printf("\nEnter cash again: ");
scanf("%f",&cash);
float solo_change=cash-total;
printf("\nTotal Cash Received: %.2f",cash);
printf("\nThe general Change: %.2f",solo_change);
exit(1);
else if(choice2=='Y'||choice2=='y')
printf("Enter total number of friends: ");
scanf("%d",&friends);
printf("Total payment for each friend: %.2f",t_payment=total/friends);
printf("\n");
break;
printf("\n");
}
}
for(j=0;j<friends;j++)
printf("\nEnter the cash of friend %d: ",j+1);
scanf("%f",&friends_money);
while(friends_money<t_payment)
printf("\nInvalid Cash");
printf("\nEnter cash again: ");
scanf("%f",&friends_money);
printf("Change of friend %d = %.2f",j+1,friends_change=friends_money-t_payment);
printf("\n");
sum_cash+=friends_money;
gen_change += friends_change;
printf("______________________________________\n");
printf("Total Cash Received: %.2f",sum_cash);
printf("\nThe general Change: %.2f",gen_change);
return 0;
}
//RESULTS//
|
|
|
|
|
v