I want use write a loop that the user can enter int. the user can enter infinite number of int until they enter -1. And I want to use array to store the input int except -1. how can I write the code? Below is the code that I have written without array. can someone help me?
int d;
while(d>=0){
cout<<"Add divisor: ";
cin>>d;
An array can only hold a fixed amount of numbers, so if the user can enter an infinite number of integers you can not be sure that you can store them in an array. If you really need an infinate number of inputs, google for "std::vector" or "linked list".
Also try posting the code that you currently have (use the "<>" button to format it as source code) and describing the problem that you encounter in your own words. It will make the answers you get so much more useful.
The code will work,but I will suggest that you initialize "d" with:
1 2 3
int d = 0;
int d(0);
int d{ 0 };
either way will work, I prefer the third one.
If you want to print out what you enter just put the code after the break statement: std::cout << "d = " << d << endl;.
If you want to use an array, define the array before the while loop. You will also need a counter variable to use the array. The code would be something like: