[Solved] Replacing the goto Statement


Please let me know if I missed something

#include "stdafx.h"
#include <iostream>

using namespace std;


void Print(int count, int countSub, int rolePerGroup, int userCount, int userPerGroup)
{
for(int roleCount = 1; roleCount<=rolePerGroup; roleCount ++)
{ 
    if(userPerGroup == 0) 
    {
        cout<<"Parent groups are: "<< count <<" | "<<"Sub group are :     "<<countSub<<" | "<<"Role per Sub group are : "<< roleCount <<" | "<<"User per role are : "<< userCount <<endl;
        continue;
    }

    for(userCount = 1; userCount<=userPerGroup; userCount ++)
        cout<<"Parent groups are: "<< count <<" | "<<"Sub group are : "<<countSub<<" | "<<"Role per Sub group are : "<< roleCount <<" | "<<"User per role are : "<< userCount <<endl;
}
}

int main()
{ 
int userCount = 0;
int roleCount = 0;
int parentGroup;
cout<<"enter a number of parentGroup"<< endl;
cin>> parentGroup;

if (parentGroup == 0) 
{ 
    cout<<"Parent Group should not be zero"<<endl;
    exit(EXIT_FAILURE);
}

int subGroup;
cout<<"enter a number sub Group"<< endl;
cin>> subGroup;
int rolePerGroup;
cout<<"enter a number role per Sub Group"<< endl;
cin>> rolePerGroup;

if (rolePerGroup == 0)
{
    cout<<"Role per Group should not be zero"<<endl;
    exit(EXIT_FAILURE);
}

int userPerGroup;
cout<<"enter a number user per Role"<< endl;
cin>> userPerGroup;


for(int count=1;count <= parentGroup; count ++)
{
    if(subGroup == 0) 
    {
        Print( count, 0, rolePerGroup, userCount, userPerGroup);
        continue;
    }

    for(int countSub = 1;countSub<=subGroup; countSub ++)
    { 
        Print( count, countSub, rolePerGroup, userCount, userPerGroup);
    }
}
}

1

solved Replacing the goto Statement