#include <stdio.h>
/*
Write a C program to display the Product information and Payment mode
of a customer using bit fields. * The product information are
P_rice=0, P_wheat=1, P_dall=2, P_sugar=3, Cash=5 and Card=6 *
The bit fields member functions are Ptype, Pmode and *Pname is character type
*/
#define p_rice 0
#define p_wheat 1
#define p_dalll 2
#define p_sugar 3
#define p_Cash 5
#define p_Card 6
main(void)
{
unsigned char Info=0x00, Flag=1;
int item;
while(Flag)
{
item=-1;
while(item<1 || item>4)
{
printf("\nPress 1 for Rice ");
printf("\nPress 2 for Wheat ");
printf("\nPress 3 for Dall ");
printf("\nPress 4 for Sugar ");
printf("\nEnter Option (1, 2, 3 or 4): "); scanf("%d",&item);
if(item==1) Info = 0x01;
if(item==2) Info = 0x02;
if(item==3) Info = 0x04;
if(item==4) Info = 0x08;
}
item=-1;
while(item<5 || item>6)
{
printf("\nPress 5 for Cash ");
printf("\nPress 6 for Card ");
printf("\nEnter Option (5 or 6): "); scanf("%d",&item);
if(item==5) Info = Info | 0x20;
if(item==6) Info = Info | 0x40;
}
if((Info & 0x0F) == 0x01) printf("\n\nItem Ordered = Rice");
if((Info & 0x0F) == 0x02) printf("\n\nItem Ordered = Wheat");
if((Info & 0x0F) == 0x04) printf("\n\nItem Ordered = Dall");
if((Info & 0x0F) == 0x08) printf("\n\nItem Ordered = Sugar");
if((Info & 0x60) == 0x20) printf("\n\nPayment by: Cash");
if((Info & 0x60) == 0x40) printf("\n\nPayment by: Card");
Flag=-1;
while(Flag<0 | Flag>1)
{
printf("\n\nPres 1 to continue or 0 to quit: "); scanf("%d",&Flag);
}
}
}
Comments
Leave a comment