Have a Read!

Hi Everyone.
The idea for this page is to provide new c users simple c tutorials to learn how to develop the logic and more importantly correct way to write syntax.
ENJOY !!!

Sunday, January 30, 2011

C PROGRAM FOR A BAKERY

The following represents a simple bakery program that keeps the update of sales made.Run it first then you will have a better understanding of whats going on  in the code.
#include<stdio.h>//standard input
int main()//entry to main fuction
{
int bread=15; // initial bread available
int breadsold,remainingbread=15,breadprofit=0; // variables for bread
int egg=72; // initial egg available
int eggsold,remainingegg=72,eggprofit=0; // variables for egg
int butter=25;//initial butter available
int buttersold,remainingbutter=25,butterprofit=0;//variables for bread
int milk=50; // initial milk
int milksold,remainingmilk=50,milkprofit=0;//variables for milk
int item,x,profit1=0,profit2=0,profit3=0,profit4=0,megaprofit=0;//variables for profit and items selected
printf("\n\n*******************************************************************************\n");
printf("\t\t\t      WELCOME TO BAKERY\n ");
printf("\t     CURRENTLY WE HAVE THE FOLLOWING ITEMS IN QUANTITY\n");
printf("\t        BREAD         EGG        BUTTER        MILK\n");
printf("\t         %d            %d         %dkg          %dl\n\n\n",bread,egg,butter,milk);
printf("Current Market Rates for Respected Items are as Follow:\nBread=40Rs\nEgg=4Rs\nButter=50Rs/kg\nMilk=50Rs/ltr\n\n\n\n");
printf("What would you like to sell\n");  // Here user selects what to sell
printf("1 for Bread\n");
printf("2 for Egg\n");
printf("3 for Butter\n");
printf("4 for Milk\n");
printf("Your choice:");
scanf("%d",&item);
if(item>4 || item<=0)
   {printf("Not a valid entry"); }
else{
for(x=0;x!=6;x)  // Only loop so that user can sell more
{
   if (item==1) // 'Bread if'
      {
         printf("\nhow much bread u want to sell\n");
         scanf("%d",&breadsold);
            if (breadsold>remainingbread || breadsold<0)
            {printf("We dont have this much Bread to sell kindly keep it less or equal to quanitiy available\n");}
            else
            {remainingbread=bread-breadsold; //tracker of bread available for next entry in the loop
            bread=remainingbread;
            profit1= breadsold*40;//calculates profit of this sale
            breadprofit=profit1 + breadprofit;//for total megaprofit
            printf("\nThe quantity of Bread u have sold is %d\nThe profit for this sale is %dRs\nNow you have %d bread remaining to sell\n\n",breadsold,profit1,remainingbread);
             megaprofit=breadprofit+eggprofit+butterprofit+milkprofit ;}
      }// 'End Bread if'
  if (item==2) //"Egg if"
     {
       printf("how much Egg u want to sell\n");
       scanf("%d",&eggsold);
        if(eggsold>remainingegg || eggsold<0)
           {printf("We dont have this much Egg to sell kindly keep it less or equal to quantity available\n");}
         else{
         remainingegg=egg-eggsold;//traker for egg available
         egg=remainingegg;
         profit2=eggsold*4;//profit of this sale
         eggprofit=profit2+eggprofit;//total eggprofit for megaprofit
         printf("\nThe quantity of Egg u have sold is %d\nThe profit for this sale is %dRs\nNow you have %d Egg remaining to sell\n\n",eggsold,profit2,remainingegg);
         megaprofit=breadprofit+eggprofit+butterprofit+milkprofit ;}
    } // End " Egg if"
  if (item==3)//"Butter if"
  {
       printf("how much Butter u want to sell\n");
       scanf("%d",&buttersold);
          if(buttersold>remainingbutter || buttersold<0 )
           {printf("We dont have this much Butter to sell kindly keep it less or equal to quantity available\n");}
          else {
           remainingbutter=butter-buttersold;//tracker of butter available
           butter=remainingbutter;
           profit3=buttersold*50;//profit for this sale
           butterprofit=profit3+butterprofit;//total profit ofbutter for megaprofit
           printf("\nThe quantity of Butter u have sold is %dkg\nThe profit for this sale is %dRs\nNow you have %dkg Butter remaining to sell\n\n",buttersold,profit3,remainingbutter);
           megaprofit=breadprofit+eggprofit+butterprofit+milkprofit ;}
  } //End "butter if"
  if (item==4) // " Milk if"
  {
  printf("how much Milk u want to sell\n");
  scanf("%d",&milksold);
     if(milksold>remainingmilk || milksold<0)
     {printf("We dont have this much Milk to sell kindly keep it less or equal to quantity available\n");}
     else {
      remainingmilk=milk-milksold;//tracker of milk availabe
      milk=remainingmilk;
      profit4=milksold*50;//this sale profit
      milkprofit=profit4+milkprofit;//for megaprofit
      printf("\nThe quantity of Milk u have sold is %dltr\nThe profit for this sale is %dRs\nNow you have %dltr Milk remaining to sell\n\n",milksold,profit4,remainingmilk);
      megaprofit=breadprofit+eggprofit+butterprofit+milkprofit ;}
  } //End "Milk if"
if (item==5)
{printf("Profit earned uptill now is %dRs",megaprofit);}
printf("\n\n\nWhat would you like to sell\n"); // portion for sale after another or end
printf(" 1 for Bread\n");
printf(" 2 for Egg\n");
printf(" 3 for Butter\n");
printf(" 4 for Milk\n");
printf("OR\n");
printf(" 5 to view Profit earned uptill now\n");
printf(" 6 if you are willing to Exit sale\n");
printf("Your choice:");
scanf("%d",&item); // end portion
if( item<=0 || item>6)
{printf("\nNOTE : There is no such choice\nPlease select again\n");}
if(item==6) // if 6 is entered the loop ends
{ x=6;
megaprofit=breadprofit+eggprofit+butterprofit+milkprofit ; //calculates the profits of all sales made
printf("\n\n\nThe Profit you earned for today's sale is %dRs\n You have\n %d BREAD\n %d EGG\n %dkg Butter \n %dltr MIlk left to sale\n\n\n \t\t\tHAVE A GOOD DAY\n\n\n",megaprofit,remainingbread,remainingegg,remainingbutter,remainingmilk); }
//displays the total profit
}//end For loop
}
printf("\n\n*******************************************************************************\n");
return 0;} //end main funtion
Related Posts with Thumbnails