C code assignment
You work for Whole Foods Market and your boss asks you to develop a mini cashier. Write a C program to do the followings:
Hint: we do not know how many items each customer has; therefore, your program should set a condition to stop or continue accepting items (for example: a char variable that sets to “c” to continue or “s” to stop).
For example:
customer #1 card = {milk, apple, pizza, apple tart}
Customer #2 card = {orange, yogurt, butter, beer, avocado, raspberries}
Customer #3 card = {roses, chocolate, greeting card}
Expected Output:
Customer #1: $14.78
Customer #2: $20.67
Customer #3: $34.56
**** Use of control flow (for loop, while loop, if-then-else) is REQUIRED ****
**** Prompt accordingly or lose 5 points right away ****
#include <stdio.h>
#include <stdlib.h>
#define TAX 5 /// 5% TAX
#define MAX 20
/// declare items
const char* itemSet[]={"milk", "apple ", "pizza", "apple
tart","orange", "yogurt", "butter", "beer", "avocado",
"raspberries","roses", "chocolate", "greeting card"};
/// prieceSet[0] is price for itemSet[0]
float priceSet[]={2,4,1,5,7,3.3,6.1,1.9,8,9,4.2,5.3,7};
void printMenu(){
int countOFItems=0; ///size of
countOFItems=sizeof(priceSet)/sizeof(float);
printf("\n\nSR.NO\tItem\t\tPrice\n");
int i=0;
for(i=0;i<countOFItems;i++){
printf("\n%d\t%s\t\t%f",i+1,itemSet[i],priceSet[i]);
}
printf("\n");
}
struct Customer{
///char* array to store items buy by that customer
char* items[MAX];
///count of items bought
int cnt;
///total price
float total_price;
};
/*
function to display all customers cart and amount bill that he have
to pay
*/
void printCustomer(struct Customer cust[],int size){
int i=0,index=0;
for(index=0;index<size;index++){ /// for all customers
printf("\nItems Bought by customer %d :\n",index);
for(i=0;i<cust[index].cnt;i++){ /// for all items of that
particular customer
printf("\n%s",cust[index].items[i]);
}
printf("\nAmount to pay = $ %f:",cust[index].total_price);
printf("\nTax to pay = %d Percent: ",TAX);
printf("\nTotal amount to pay = $ %f ",
cust[index].total_price+(cust[index].total_price)*((float)TAX/100)
);
printf("\n\n**********************\n");
}
}
int main()
{
int CustomerCount=0;
///ask user how many customers?
printf("\nEnter total no of customers :");
scanf("%d",&CustomerCount);
struct Customer customer1[CustomerCount];
///declare structre to store all cutomers
int index=0;
for (index=0;index<CustomerCount;index++) ///for all
customers
{
printf("\nFor customer :%d\n",index);
///initialize cnt and price to 0
customer1[index].cnt=0;
customer1[index].total_price=0;
///iterate till user not enters s to Stop
char choice='c';
int itemIndex=0;
while(1)
{
printf("\nDo you want to continue ? Enter c to continue or s to
stop :");
scanf(" %c",&choice);
if(choice=='s' || choice=='S')
break; /// if user wants to stop then break inner while loop
if(choice!='c' && choice!='C' )
{
printf("\nInvalid choice"); /// if user enterd other thaan s /
c
continue;
}
/// add item SR NO from user
printMenu();
printf("\nEnter the SR.NO of item e.g -> 1 for item %s\n
",itemSet[0]);
scanf("%d",&itemIndex);
///add to structure member
customer1[index].items[customer1[index].cnt]=itemSet[itemIndex-1];
//itemIndex-1 bacause we hav started SR.NO numbers from 1 and index
of array are from 0
customer1[index].cnt++; ///incrent count of items boughts
customer1[index].total_price=customer1[index].total_price +
priceSet[itemIndex-1]; ///increment total price by items price
} ///end while
}/// for loop for customers
///print all customers cart and bill
printCustomer(customer1,CustomerCount);
return 0;
}
C code assignment You work for Whole Foods Market and your boss asks you to develop...