This is my program. I am using CodeBlocks. The errors that it shows me are the following:
- 26 - expected primary-expression before 'int'.
- 26 - expected ']' before 'int'.
- 26 - expected ')' before 'int'.
- 26 - expected initializer before 'int'.
The code is as follows:
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <cmath>
class Network
{
public:
int ip[4],mask,cont,nhost,nred,pot;
};
void head()
{
std::cout << "\t\tSubnetting Console" << std::endl;
};
int cant(int a)
{
head();
std::cout << "Cuantas redes hay?\n" << std::endl;
std::cin >> a;
system("cls");
return a;
};
void proc1(Network net[],int n)
{
head();
std::cout << "Cuantos host tiene cada red\n" << std::endl;
for(int b=0; b<n;b++)
{
std::cout<<"R"<<b+1<<": ";
std::cin>>net[b].nhost;
std::cout << "nhost-Listo" << std::endl;
net[b].nred=b+1;
std::cout << "nred-Listo" << std::endl;
net[b].pot=1;
std::cout << "pot-Listo" << std::endl;
net[b].cont=0;
std::cout << "cont-Listo" << std::endl;
while((net[b].pot-2)<net[b].nhost)
{
net[b].pot*=2;
net[b].cont++;
}
net[b].mask=32-net[b].cont;
std::cout << "mask-Listo" << std::endl;
}
system("cls");
};
void SetIP(Network net[],int n)
{
int bmask, bip[4];
long int num=0;
for(int z=0;z<n;z++){num+=net[z].pot;}
if(num<65536){bmask=16; bip[0]=192;bip[1]=168;bip[2]=0;bip[3]=0;} //Si la red nesecita menos de 65,536 hosts se usa 192.168.0.0/16
else if(num<1048576){bmask=12; bip[0]=172;bip[1]=16;bip[2]=0;bip[3]=0;} //Si la red nesecita menos de 1,048,576 hosts se usa 172.16.0.0/12
else{bmask=8; bip[0]=10;bip[1]=0;bip[2]=0;bip[3]=0;} // En cualquier otro caso se usa el ip 10.0.0.0/8
if(bmask==16)
{
for(int a=17;a<32;a++)
{
for(int b=0;b<n;b++)
{
if(net[b].mask==a)
{
net[a].ip[0]=bip[0];
net[a].ip[1]=bip[1];
net[a].ip[2]=bip[2];
net[a].ip[3]=bip[3];
if((32-a)>=8)
{
bip[2]+=pow(2,((32-a)-8));
}
else
{
bip[3]+=pow(2,(32-a));
}
if(bip[3]>255)
{
bip[2]+=1;
bip[3]-=256;
}
if(bip[2]>255)
{
bip[1]+=1;
bip[2]-=256;
}
}
}
}
}
else if(bmask==12)
{
for(int a=13;a<32;a++)
{
for(int b=0;b<n;b++)
{
if(net[b].mask==a)
{
net[a].ip[0]=bip[0];
net[a].ip[1]=bip[1];
net[a].ip[2]=bip[2];
net[a].ip[3]=bip[3];
if((32-a)>=16)
{
bip[1]+=pow(2,((32-a)-16));
}
else if((32-a)>=8)
{
bip[2]+=pow(2,((32-a)-8));
}
else
{
bip[3]+=pow(2,(32-a));
}
if(bip[3]>255)
{
bip[2]+=1;
bip[3]-=256;
}
if(bip[2]>255)
{
bip[1]+=1;
bip[2]-=256;
}
if(bip[1]>255)
{
bip[0]+=1;
bip[1]-=256;
}
}
}
}
}
else
{
for(int a=9;a<32;a++)
{
for(int b=0;b<n;b++)
{
if(net[b].mask==a)
{
net[a].ip[0]=bip[0];
net[a].ip[1]=bip[1];
net[a].ip[2]=bip[2];
net[a].ip[3]=bip[3];
if((32-a)>=24)
{
bip[0]+=pow(2,((32-a)-24));
}
else if((32-a)>=1)
{
bip[1]+=pow(2,((32-a)-16));
}
else if((32-a)>=8)
{
bip[2]+=pow(2,((32-a)-8));
}
else
{
bip[3]+=pow(2,(32-a));
}
if(bip[3]>255)
{
bip[2]+=1;
bip[3]-=256;
}
if(bip[2]>255)
{
bip[1]+=1;
bip[2]-=256;
}
if(bip[1]>255)
{
bip[0]+=1;
bip[1]-=256;
}
}
}
}
}
};
void prnt(Network net[],int n)
{
head();
for(int b=0;b<n;b++)
{
std::cout<<"R"<<b+1<<": "<<net[b].ip[0]<<"."<<net[b].ip[1]<<"."<<net[b].ip[2]<<"."<<net[b].ip[3]<<"/"<<net[b].mask<<std::endl;
}
};
int main()
{
int x,y;
x = cant(x);
Network* red[x];
y=((sizeof(red))/(sizeof(red[0])));
proc1(red[x],y);
//SetIP(red[x],y);
//prnt(red[x],y);
return 0;
}