In this program the case 4 of report function is not working.It directly executes the default.All othere case executes properly.There are othere functions also.But the only thing that doesn't work is this.The program is too long.So i cannot submit the whole program.
PROGRAM:
void report()
{int choice;
cout<<"\n\t REPORT \n";
cout<<"\n1.View Item Individualy";
cout<<"\n2.View All Items";
cout<<"\n3.Sales Report Of 1 Item";
cout<<"\n4.Sales Report Of All Items";
cout<<"\n5.Go Back To Main Menu";
cout<<"\nENTER YOUR CHOICE(1-5)";
cin>>choice;
switch(choice)
{case 1:int num;
clrscr();
cout<<"\n\n\tPLEASE ENTER THE ITEM NO";
cin>>num;
display_sp(num);
break;
case 2:display_all();
break;
case 3:clrscr();
int nm,pum=0;
cout<<"\nEnter The Item No. Whose Sale Report To Be Seen";
cin>>nm;
ifstream ifile;
ifile.open("stock.dat",ios::binary|ios::in);
while(ifile.read((char*)&st,sizeof(st)))
{if(st.retitno()==nm)
{clrscr();
st.disprep();
pum=1;
}
}
ifile.close();
if(pum==0)
cout<<"\n\nrecord not exists";
getch();
break;
case 4:
clrscr();
ifstream ifile2;
ifile2.open("stock.dat",ios::binary|ios::in);
cout<<"\nITNo.\tItemName\t\tQtysold\tPrice\tqtyr\n\n";
cout<<"=================================================================\n";
while(ifile2.read((char*)&st,sizeof(st)))
{ cout<<st.retitno()<<"\t\t"<<st.retitname()<<"\t\t"<<st.retctr()<<"\t"<<st.retlprice()<<st.retitqty()<<endl;
}
ifile2.close();
break;
case 5:menu();
break;
default:cout<<"\nWRONG CHOICE";
cout<<"\a";
report();
}
}
//THE MAIN FUNC. OF PROGRAM MENU
void main()
{int ch;
do{clrscr();
gotoxy(7,4);
cout<<"******************************************************************";
gotoxy(31,5);
cout<<" LULU HYPER MARKET";
gotoxy(7,6);
cout<<"------------------------------------------------------------------";
gotoxy(35,7);
cout<<"MAIN MENU";
gotoxy(7,8);
cout<<"------------------------------------------------------------------";
cout<<"\n\n\t1.SALES DEPARTMENT";
cout<<"\n\n\t2.STOCK DEPARTMENT";
cout<<"\n\n\t3.REPORT";
cout<<"\n\n\t4.EXIT";
gotoxy(7,17);
cout<<"===================================================================";
cout<<"\n\tPLEASE SELECT YOUR OPTION(1-4):";
gotoxy(7,19);
cout<<"*******************************************************************\n\t";
cin>>ch;
switch(ch)
{case 1: clrscr();
billing();
getch();
break;
case 2: stockmenu();
break;
case 3: report();
break;
case 4: exit(0);
default :cout<<"\a";
}
}while(ch!=4);
}
You can't define a variable inside a switch statement unless it's within braces. So in cases 3 and 4, either move the variables int nm, pnum=0 and ifstream ifile2 above the switch statement, or put the code of each case inside { and }