i do it because i need it... you want me to post the whole code?
and also, it's just that i'm not able to use the globally declared variables in the function.. that is all. i don't think it has anything to do with the do-while loops.. :/
@coder777 asked:
what has this code to do with your original question?
You still haven't made that clear.
"and also, it's just that i'm not able to use the globally declared variables in the function.. that is all. i don't think it has anything to do with the do-while loops.. :/"
If indeed your problem is with scope, that is the more reason to show your code in context.
You can't have that do block there outside a function, with all the problems in the code you've posted, we can't see where you've gone wrong or which of the problems you're complaining about.
If indeed this is a fragment from inside a function, then you are defining functions within functions and you've got some thing like:
1 2 3 4 5 6 7 8 9
do
{
do
{
siwtch()
{
} whilereturn;
}
Please post meaningful and formatted code.
There is no switch/while construct in C++, so if this is indeed representative of your code, how can the do-while loops not be a contributing factor?
i have to make a project on mass management and i decided to make it on how salary is calculated here in India..
i could post the whole code if you want it.. i have a lot of errors.. but it's just tooooooo long and i don't want to bother you people.. if you give a thumbs up, i shall do that :)
double ba_sal, HRA, g_sal, sal;
int DA, TA, PF, IT, no2, no, no3;
std::string str, no1, age;
void CreRe();
void ViewRe();
void YrSal();
void EditSal();
do
{std::cout<<"Menu \n 1. Create Record \n 2. View All Records \n 3. Yearly Salary \n 4. Edit Salary \n 5. Exit \n Please enter the number:";
std::cin>>no;
switch(no)
{
case 1 : CreRe();
break;
case 2 : ViewRe();
break;
case 3 : YrSal();
break;
case 4 : EditSal();
break;
default: std::cout<<"Please Check Number Entered";
no=0;
}
}while(no==0);
getch();
return 0;
}
void CreRe();
{
std::cout<<"CREATE RECORDS \n";
std::cout<<"Enter Record Number: ";
std::cin>>no1;
std::cout<<"\n Enter name: ";
std::cin>>str;
std::cout<<"\n Enter age:";
std::cin>>age;
std::cout<<"\n 1. Managing Director \n 2. Director \n 3. General Manager \n 4. Deputy General Manager \n 5. Chief Manager \n 6. Senior Executive \n 7. Executive \n 8. Officer \n 9. Clerk \n 10. Sub-Staff \n Enter designation number : ";
std::cin>>no2;
ba_sal=0;
do
{
switch(no2)
{
case 1 : std::cout<<"\n MANAGING DIRECTOR";
ba_sal=800000;
break;
case 2 : std::cout<<"\n DIRECTOR";
ba_sal=500000;
break;
case 3 : std::cout<<"\n GENERAL MANAGER";
ba_sal=300000;
break;
case 4 : std::cout<<"\n DEPUTY GENERAL MANAGER";
ba_sal=150000;
break;
case 5 : std::cout<<"\n CHIEF MANAGER";
std::cout<<"\n Enter Pay:";
std::cin>>ba_sal;
if(ba_sal<80000||ba_sal>100000)
{
ba_sal=0;
std::cout<<"\n CHECK SALARY";
}
break;
case 6 : std::cout<<"\n SENIOR EXECUTIVE";
std::cout<<"\n Enter Pay:";
std::cin>>ba_sal;
if(ba_sal<65000||ba_sal>85000)
{
ba_sal=0;
std::cout<<"\n CHECK SALARY";
}
break;
case 7 : std::cout<<"\n EXECUTIVE";
std::cout<<"\n Enter Pay:";
std::cin>>ba_sal;
if(ba_sal<50000||ba_sal>80000)
{
ba_sal=0;
std::cout<<"\n CHECK SALARY";
}
break;
case 8 : std::cout<<"\n OFFICER";
std::cout<<"\n Enter Pay:";
std::cin>>ba_sal;
if(ba_sal<40000||ba_sal>75000)
{
ba_sal=0;
std::cout<<"\n CHECK SALARY";
}
break;
case 9 : std::cout<<"\n CLERK";
std::cout<<"\n Enter Pay:";
std::cin>>ba_sal;
if(ba_sal<25000||ba_sal>40000)
{
ba_sal=0;
std::cout<<"\n CHECK SALARY";
}
break;
case 10: std::cout<<"\n SUB-STAFF";
std::cout<<"\n Enter Pay:";
std::cin>>ba_sal;
if(ba_sal<15000||ba_sal>25000)
{
ba_sal=0;
std::cout<<"\n CHECK SALARY";
}
break;
default: std::cout<<"Please Check Number.";
ba_sal=0;
}
}while(ba_sal==0);
if(no2>4&&no2<11)
{
DA=ba_sal/10;
HRA=ba_sal/4;
TA=3000;
PF=ba_sal/20;
}
else
{
DA=0;
HRA=0;
TA=0;
PF=ba_sal/20;
}
g_sal=ba_sal+DA+HRA+TA;
{
if((g_sal*12)-100000>800000)
{
IT=g_sal/3.3;
}
elseif((g_sal*12)-100000>500000&&(g_sal*12)-100000<800001)
{
IT=g_sal/5;
}
elseif((g_sal*12)-100000>200000&&(g_sal*12)-100000<500001)
{
IT=g_sal/10;
}
else
IT=0;
}
std::cout<<"\n Deductions = Rs."<<PF+IT;
sal=g_sal-PF-IT;
std::cout<<"\n Take-away salary = Rs."<<sal;
}
this is the code along with only one function.. i'm not able to use the variables like g_sal, PF and IT in the function's body... it says that the variable has not been declared in that scope...
i need the variables to retain their value for the other functions too... how do i do that? return the values from the function CreRe?
i have included string.
and i have provided implementation for the functions before itself...