Use of static key world in c++
Sep 23, 2010 at 9:54pm UTC
i am writing this a program in which i want to calculate the total bill of different products buy by customer. For this purpose i use static key world but it is not working.
My Code Is as Follow:
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 38 39 40 41
if ((ct=='e' || ct=='E' )&& (len==1))
{
system("cls" );
cout<<'\n' ;
cout<<'\n' ;
cout<<'\n' ;
cout<<" ! NEW__CUSTOMER_ENTRY !" ;cout<<'\n' ;
cout<<" ======================" ;
cout<<'\n' ;
cout<<'\n' ;
cout<<'\n' ;
cout<<'\n' ;
cout<<"Enter Name of Custmer :: " ;
cin>>nam;
size=strlen(nam);
infile.seekp(92,ios::beg);
infile.write(nam,size);
cout<<'\n' ;
cout<<'\n' ;
cout<<'\n' ;
cout<<'\n' ;
cout<<"Enter No of Different Itmes Buy :: " ;
cin>>no;
while (j<=no)
{
cout<<'\n' ;
cout<<'\n' ;
cout<<'\n' ;
cout<<"Enter Per Unit Price of " ;cout<<j;cout<<" Item :: " ;
cin>>pri;
cout<<'\n' ;
cout<<'\n' ;
cout<<'\n' ;
cout<<"Enter No Of Itmes :: " ;
cin>>qno;cout<<'\n' ;
cal=pri*qno; ////cal is static////
cout<<cal;
j++;
}
cout<<cal2=cal+cal;
It just add up the last calculation.
alto in STATIC variable previous value is save but in this case it is not working?
Sep 23, 2010 at 10:10pm UTC
Each time you use the assignment operator you change the value of the variable, it doesn't matter how the variable is stored
Sep 24, 2010 at 7:39am UTC
Then please tell me how can i do this?
Sep 24, 2010 at 7:57am UTC
cal=pri*qno; ////cal is static////
The above statement do direct assignment. If you want to add them all up use below.
cal+=(pri*qno);
Sep 24, 2010 at 10:14am UTC
thnx i solve it
Topic archived. No new replies allowed.