Docsity

C Program for a Simple Grocery Store, Exercises of Computer Fundamentals

Toggle sidebar
bg1
//it is the first step of program in which library will be included
#include<stdio.h>
//it is the main entry point of program
int main()
{
//it is the declaration of variables used in function
int bread,eggs,milk,butter,a,b,c,d,f,w,i,h,k,flag,add=0;
float g,e,j;
//it is the initialization of variables
a=50;
b=240;
c=20;
d=30;
bread=40;
milk=37;
eggs=7;
butter=30;
//this is the start do-while statement
do
{
flag=1;
printf("name of item\tamount present\t\tprice\n");
printf("bread\t\t%d packets\t\t40\n",a);
printf("egg(s)\t\t%d\t\t\t7\n",b);
printf("milk\t\t%d litres\t\t37\n",c);
printf("butter\t\t%d kg\t\t\t30\n",d);
printf("what do you want to sell\npress 1 for bread\npress 2
for egg\npress 3 for milk\npress 4 for butter\npress any alphabet to
exit\n
");
flag=scanf("%f",&g);
if(flag==1)
{
k=g;
if(g-k==0)
{
//this if-statement will take us in bread portion
if(g==1)
{
w=0;
printf("how many packets of bread do you
want to sell\n");
scanf("%f",&e);
w=e;
//this if statement is meant for checking validity of local
input
if(e<=a&&e-w==0&&e>0)
{
a=a-e;
add+=((bread*50)-(bread*a));
printf("packets of bread
remaining=%d\n",a);
printf("you have sold bread of %d
Rs\n",((bread*50)-(bread*a)));
docsity.com
pf3
pf4
pf5
pf8

Partial preview of the text

Download C Program for a Simple Grocery Store and more Exercises Computer Fundamentals in PDF only on Docsity!

//it is the first step of program in which library will be included #include<stdio.h> //it is the main entry point of program int main() { //it is the declaration of variables used in function int bread,eggs,milk,butter,a,b,c,d,f,w,i,h,k,flag,add=0; float g,e,j; //it is the initialization of variables a=50; b=240; c=20; d=30; bread=40; milk=37; eggs=7; butter=30; //this is the start do-while statement do { flag=1; printf("name of item\tamount present\t\tprice\n"); printf("bread\t\t%d packets\t\t40\n",a); printf("egg(s)\t\t%d\t\t\t7\n",b); printf("milk\t\t%d litres\t\t37\n",c); printf("butter\t\t%d kg\t\t\t30\n",d); printf("what do you want to sell\npress 1 for bread\npress 2 for egg\npress 3 for milk\npress 4 for butter\npress any alphabet to exit\n "); flag=scanf("%f",&g); if(flag==1) { k=g; if(g-k==0) { //this if-statement will take us in bread portion if(g==1) { w=0; printf("how many packets of bread do you want to sell\n"); scanf("%f",&e); w=e; //this if statement is meant for checking validity of local input if(e<=a&&e-w==0&&e>0) { a=a-e; add+=((bread50)-(breada)); printf("packets of bread remaining=%d\n",a); printf("you have sold bread of %d Rs\n",((bread50)-(breada)));

printf("press 1 to see items remaining\npress any key to see total sale uptill now\n"); scanf("%f",&j); w=j; //this if statement is meant for checking validity of local input if(j-w==0&&(j==1||j==2)) { //this if-statement will show the required thing if(j==1) { printf("number of packets of breads=%d\nnumber of eggs=%d\nnumber of packets of milk=%d\nnumber of packes of butter=%d\n",a,b,c,d); } if(j==2) { printf("your total sale uptill now is=%d\n",add);

} } //if input else { printf("invalid choice\n"); } // } else { printf("invalid choice\n"); } //it is the end of if statement for bread portion } //this if-statement will take us in egg(s) portion if(g==2) { w=0; printf("how many egg(s) do you want to sell\n"); scanf("%f",&e); w=e; //it is the check for validity of input if(e-w==0&&e<=b&&e>0) { b=b-e; add+=((eggs240)-(eggsb)); printf("no. of eggs remaining=%d\n",b); printf("you have sold egg of %d Rs\n",((eggs240)-(eggsb))); printf("press 1 to see remaining items\npress 2 to see total sale\n"); scanf("%f",&j);

//it is the check for validity of input if(j-w==0&&(j==1||j==2)) { if(j==1) { printf("number of packets of breads=%d\nnumber of eggs=%d\nnumber of packets of milk=%d\nnumber of packes of butter=%d\n",a,c,b,d); } else { printf("your total sale uptill now=%d\n",add);

} } //this statement is in accordance with validity check if- statement else { printf("invalid choice\n"); } //this statement is in accordance with validity check if- statement } else { printf("invalid choice\n"); } //it is the end of if statement for milk portion } //this if-statement will take us in butter portion if(g==4) { w=0; printf("how many packets do you want to sell\n");

scanf("%f",&e); w=e; //it is the check for validity of input if(e-w==0&&e<=d&&e>0) { d=d-e; add+=((butter30)-(butterd)); printf("no. of packets of butter remaining=%d\n",d); printf("you have sold butter of %d amount\n",((butter30)-(butterd))); printf("press 1 to see remaining items\npress 2 to see total sale\n"); scanf("%f",&j); w=j; //it is the check for validity of input

if(j-w==0&&(j==1||j==2)) { if(j==1) { printf("number of packets of breads=%d\nnumber of eggs=%d\nnumber of packets of milk=%d\nnumber of packes of butter=%d\n",a,b,c,d); } else { printf("your total sale uptill now=%d\n",add);

} } //this statement is in accordance with validity check if- statement else { printf("invalid choice\n"); } //it is the end of validity check if-statement } else { printf("invalid choice\n"); } //it is the end of if statement for butter portion } if(g!=1&&g!=2&&g!=3&&g!=4) { printf("invalid choice\n"); } } //this statement is in accordance with validity check if-statement else { printf("invalid choice\n"); } printf("press 1 to continue or numeric key to exit\n"); scanf("%d",&h); } //this statement is in accordance with validity check if- statement else {printf("input is invalid\n"); } } //it is the end of do-while statement while(h==1); //following set of commands will be executed on each exit from the program printf("item name\titem sold\titem remaining\t sale of item\n");