discuss dodo22222222?

Munna

New member
/*********************************************************************
* Filename: CafeMenuDesign.c
* Description: To understand how
to design menu based programs
* Author: Ravish Malhotra,
Infosys Technologies Ltd.
* Date: 30-Jun-2007
***************************
******************************************/

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include<string.h>
#define NUMBEROFEEMPLOYEES 6


#define Valid 0
#define Invalid 1


/*Declare function prototype */
void fnAddCustomer();
int fncheckValidName(char *acCustName);
int fncheckValidAmount(int iAmountTemp);
float fncalbalance(int iAmount);
void fnUpdateDuration();
void fnDisplayDetails();



/*Define the Customer structure*/
typedef struct _cust{
int iCustId;
char acCustName[25];
int iAmount;
float fBalance;
float fDurationUsed;
}Customer;

Customer gasCustomer[5];

/*Declare global variables*/

int iLastGeneratedCustomerId=1001;
int iIndex=0;

/*Declartion of Functions used*/

/******************************
***************************************
* Function: main()
* Description: To design a
menu to implement the functionality such as
* job band change,
confirm employee and report.
* Input Parameters:
* int argc - Number of
command line arguments
* char **argv - The command
line arguments passed
* Returns: 0 on success
to the operating system
****************************
*****************************************/

int main (int argc, char** argv) {




/* Delcare the loop
variable and a variable for
user's choice */
int iChoice;

do{



/* Display the menu
and get the choice from

the user */

printf("\t\t1. Add Customer \n");

printf("\t\t2. Update Duration\n");

printf("\t\t3. Display Details\n");

printf("\t\t4. Exit\n");


printf("Enter your choice: ");

scanf("%d",&iChoice);


/* Based on user's choice,
the respective functionality is
invoked */

switch(iChoice){

case 1: fnAddCustomer();

break;


case 2: fnUpdateDuration();

break;


case 3: fnDisplayDetails();

break;


case 4: /* Quit the program */

exit(0);

}



} while (iChoice != 4);



/* Return a success code
to the Operating System */
return 0;
}




void fnAddCustomer(){
char acCustomerName[24];
int iAmount;
int iRet1;
int i=0;


if(iIndex<5)
{

printf("\nEnter the Customer details:\n");

printf("\nCustomer Name");

fflush(stdin);

scanf("%s",&acCustomerName);

/*check if name is valid*/

iRet1=fncheckValidName(acCustomerName);


if(iRet1==1)
{

exit(0);
}


printf("\nAmount");

scanf("%d",&iAmount);


/*check if amount is valid*/

iRet1=fncheckValidAmount(iAmount);

if(iRet1==1)
{

exit(0);
}

/*Update the customer records*/

gasCustomer.iCustId
=iLastGeneratedCustomerId;


strcpy(gasCustomer
.acCustName,acCustomerName);



gasCustomer.iAmount=iAmount;



gasCustomer.fBalance=
fncalbalance(iAmount);

printf("\nkkkk%f",
gasCustomer.fBalance);



gasCustomer.fDurationUsed=0;



iLastGeneratedCustomerId++;

iIndex++;

}
}
/*********************************************************************
* Function: fncheckValidName
* Description: To check if Name is valid
* Input Parameters:
* char *acCustName :pointer to customer array
* Returns: 0 if amount valid else 1
*********************************************
************************/
int fncheckValidName
(char *acCustName){

if(strlen(acCustName)<3
|| strlen(acCustName)>24)
{
printf("\n Invalid name length");

return Invalid;
}
else
return Valid;
}

/*********************************************************************
* Function: fncheckValidAmount
* Description: To check if amount is valid
* Input Parameters:
* iAmountTemp :Amount
* Returns: 0 if amount valid else 1
*********************************************
************************/
int fncheckValidAmount(int iAmountTemp){

if(iAmountTemp<0 ||
(iAmountTemp%100)!=0)
{
printf("\n Invalid Amount");

return Invalid;}

else

return Valid;
}


/**************************************
*******************************
* Function: fncalbalance
* Description: To calculate balance
* Input Parameters:
* iAmount: Amount entered
* Returns: balance
***************************************
******************************/
float fncalbalance(int iAmount)
{
float balance;

balance = iAmount/100*10
 
Top