infinite loop

1
2
3
4
5
6
cout<<"Please enter the number of disks <max 9>: ";
cin >>d;
while (d < 0 || d >= 10){
   cout<<"Positive integers <max 9> only, please!: ";
   cin>>d;
}


So, the value of d will be from 1 to 9.

1
2
3
4
5
6
7
8
9
10
cout<<"Please enter the number of cylinders each disk has: "<<endl; 

for ( int d = 1; number <= d ; d = d + 1){
cout<<"Cylinders in Disk "<< d <<": ";
cin>>n;
while (n <= 0 ){
   cout<<"Positive integers only, please!: ";
   cin>>n;
}
}

In this loop I need it to stop according to the value of d, so if d is 9.
It should be "Cylinders in Disk 1" to "Cylinders in Disk 9." but it is running infinitely. Please help.
Last edited on
number <= d
The value of 'number' is not changed in the loop, so this will always be true (or false). I think you meant
d <= number


Edit: Smac89 got it right.
Last edited on
1
2
3
4
for ( int number = 1; number <= d ; number++) {
    cout<<"Cylinders in Disk "<< number <<": ";
    ...
}
Thank you so much Smac89!
Topic archived. No new replies allowed.