In this post I will let you know how to make bill proper bill program for ration shop or any other store . Made your own Algebraic Calculator, So, without any further delay let's get started .
Code:
#include <stdio.h>
#include<string.h>
int main()
{
int noi; //noi is for number of items
int itemnum[100]; // it is for number of items
float price[100]; //price of one item
float total = 0;
char name[40];
char date[10];
char product_name[20][20];
printf("Enter name of Customer \n");
gets(name);
printf("Enter date\n");
gets(date);
printf("Enter number of products purchased \n");
scanf("%d",&noi);
for (int i = 0; i < noi; i++)
{
printf("Enter item number \n");
scanf("%d", &itemnum[i]);
printf("Enter name of product\n");
scanf("%s",product_name[i]);
printf("Price of item first %d \n", i + 1);
scanf("%f", &price[i]);
}
for(int i=0;i<noi;i++){
total=total+price[i];
}
printf("Customer name:\t%s\tDate:\t%s\n",name,date);
printf("Product name\tProduct number\tProduct price \n");
for(int i=0;i<noi;i++){
printf("%s\t\t",product_name[i]);
printf("\t%d\t",itemnum[i]);
printf("\t%f\t\n",price[i]);
}
printf("----------------------------------------\n");
printf("Total price :\t%f\n",total);
printf("Thanks for shopping\n");
return 0;
}
Logic:
Here we first we declare noi (number of items) of type int .Then we make one array of type float that is price . And itemnum (item number) array of type int.And then we declare two array of type char name (to get name of customer) ,and date (for which date bill is make ). And then we make two dimensional string of product_name (to take name of item purchased). Then using for loop we take input of three arrays namely itemnum , price, product_name. And it take input till it is less than noi .As I told you above .Then we again use for loop to get total bill of customer . And in last for loop we print given value by user . Then total bill of customer .
Output:
Here you can see output and I think you may find this helpful in your work .
Thanks for reading
No comments:
Post a Comment