私は C++ の経験が非常に限られているため、自分のコードから "goto" 構造を置き換えたいと考えていました。リファクタリングの提案も
int main()
{
int count;
int countSub = 0;
int userCount = 0;
int roleCount = 0;
int parentGroup;
cout<<"enter a number of parentGroup"<< endl;
cin>> parentGroup;
int subGroup;
cout<<"enter a number sub Group"<< endl;
cin>> subGroup;
int rolePerGroup;
cout<<"enter a number role per Sub Group"<< endl;
cin>> rolePerGroup;
int userPerGroup;
cout<<"enter a number user per Role"<< endl;
cin>> userPerGroup;
do
{
if (parentGroup == 0)
{
cout<<"Error"<<endl;
exit(EXIT_FAILURE);
}
else
{
for(count=1;count <= parentGroup; count ++)
{
do
{
if(subGroup == 0) goto hello;
else
{
for(countSub = 1;countSub<=subGroup; countSub ++)
{
do
{
hello:
if (rolePerGroup == 0)
{
cout<<"Error"<<endl;
exit(EXIT_FAILURE);
}
else
{
for(roleCount = 1; roleCount<=rolePerGroup; roleCount ++)
{
do
{
if(userPerGroup == 0) goto print;
else
{
for(userCount = 1; userCount<=userPerGroup; userCount ++)
{
print:
cout<<"Parent groups are: "<< count <<" | "<<"Sub group are : "<<countSub<<" | "<<"Role per Sub group are : "<< roleCount <<" | "<<"User per role are : "<< userCount <<endl;
}}
userCount --;
}while(userCount < 0);
}}
roleCount --;
}while(roleCount < 0);
}}
countSub --;
}while(countSub < 0);
}}
count --;
}while(count < 0);
}