Why Runtime error:bad_alloc

int S;
cin>>S;
vector v;
float a=0.0;
float d;
while(S–){
if(S>0)
d=1/S;
else d=1;
for(a=0.0;a<=2.0;a+=d){
v.push_back(a);
}
}

Getting bad_alloc i.e runtime error.
Please any one?

In case of S>2, say S=3, the value of S inside while loop will be [2,1,0]. For S=2, d=0 (integer division) and thus, the for loop will continue forever. Thus leading to memory problem.

//