Hello Everyone my name is raymond and I living in Kuwait.In our school they do not teach us much about programming
I am having a problem with this small program can anyone please help me ? thank you so much for your time
When I run my program and add a record for the store....the rate(price) I get is when I display all the record is always 17.5 and not the value I have entered for the rate....can anyone please help.I would be very thankful
oh and BTW I do get a warning in line 27 of fuction ob.input() as
" temporary used for parameter 'num'" in this function:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
void add()
{
clrscr();
Date();
gotoxy(32,8);head1;
gotoxy(32,9);head2;
gotoxy(37,11);cout<<"ADD";
gotoxy(37,12);cout<<"-----";
box_normal(5,5,75,43);
STORE ob;
int n;
gotoxy(10,14);cout<<"ENTER THE NO OF ITEMS TO ADD TO THE COMPUTER SHOP";
input_num(n,3);
for(int i=1;i<=n;i++)
{
box_normal(5,5,75,43);
gotoxy(37,11);cout<<"ADD";
gotoxy(37,12);cout<<"-----";
gotoxy(37,8);head1;
gotoxy(37,9);head2;
gotoxy(10,15);
ofstream fout("STORE.DAT",ios::binary|ios::app);
ob.input();
fout.write((char*)&ob,sizeof(ob));
gotoxy(10,28);cout<<"The added item is";
gotoxy(10,30);cout<<"COMPNAME"<<"\tCOMPNO"<<"\tTYPE"<<"\tRATE"<<"\tQTY\n";
gotoxy(10,31);cout<<"========"<<"\t======"<<"\t===="<<"\t===="<<"\t===\n";
gotoxy(10,32);ob.output();
fout.close();
gotoxy(40,35);cout<<"PRESS ANY BUTTON TO CONTINUE...";
getch();
clrscr();
}
clrscr();
}
|
FUNCTION USED TO INPUT:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
void STORE::input()
{
int j=18;
int i=1;
char res;
cout<<"Enter the item name :";
input_string(itemname,7);
do
{
if(i==1)
{
gotoxy(10,16);cout<<"Enter the equipment number :";
}
else if(i>1)
{gotoxy(10,j++);cout<<"Enter another item number :";}
input_num(itemno,4);
res=test(itemno);
if(res=='Y')
{
gotoxy(10,j+1); cout<<"ITEM EXISTS";
}
i++;
}while(res=='Y');
gotoxy(10,j+2);cout<<"Enter the type of equipment :";
input_string(type,7);
gotoxy(10,j+3);cout<<"Enter the price of equipment :";
input_num(rate,5);
gotoxy(10,j+4);cout<<"Enter the quantity of equipment :";
input_num(qty,3);
}
|
this is one of the function where I use to take the rate:-
FUNCTION:-
void input_num(int &num,int size)
{
int i=0;
char ch;
char p[20]="\0";
do
{
ch=getch();
if((ch>='0'&&ch<='9')&&(i<size))
{
p[i]=ch;
i++;
cout<<ch;
}
else
if(ch==8&&i>0)
{
cout<<"\b"<<" "<<"\b";
i--;
}
} while(ch!=13&&i<size);
p[i]='\0';
num=atoi(p);
}
FUNCTION:on.output()
void STORE::output()
{
cprintf(" %-7s%12d %-10s%2g%4i",itemname,itemno,type,rate,qty);
}
void STORE::display(int Qty)
{
cprintf(" %-7s%12d %-10s%2g%4i",itemname,itemno,type,rate,Qty);
}
void STORE::sell(int Qty,float&price,float disc,char&ch)
{
if(qty-Qty<0)
{
gotoxy(7,20);cout<<"INSUFFICIENT QUANTITY";
ch='N';
}
else
{
qty-=Qty;
if(disc>0&&disc<100)
price=Qty*rate*disc/100.0;
else if(disc==100)
price=0;
else
price=Qty*rate;
}
}