// ------------------------------------------------------------------------
// Function: Read up to CAP integer values into array from keyboard,
// stopping when CAP values have been read or when the sentinel
// value is read.
// ------------------------------------------------------------------------
void LoadArray(int A[], int CAP, int & N, int Sentinel, string Prompt)
{
int k;
for(k=0;k<=N;k++)
{
do
{
cout << Prompt;
cin >> A[k];
} while(A[k] != Sentinel || A[k] < CAP);
}
cout << endl;
}
By using the OR operator the loop will run as long as one of the booleans evaluates to true, so if there is no Sentinel value entered it will keep going infinitely
I figured out it is not stopping because the way I have it written it is saying keep going WHILE the value of A[k] is under the cap .
what I need it to do is stop once the number of arrays written reaches the cap. How would I do that?
and also do you know how I could write it so that the value of int N is updated to be the number of values the array holds.
here is how I call the function:
1 2 3 4 5
//-| -----------------------------------------------------------
//-| 3. Load array Num with values from keyboard terminated by
//-| sentinel 7777, using prompt "Enter next value (7777 to STOP): ".
//-| -----------------------------------------------------------
LoadArray(Num, 10, Num_size, 7777, "Enter next value (7777 to STOP): ");
// ------------------------------------------------------------------------
// Function: Read up to CAP integer values into array from keyboard,
// stopping when CAP values have been read or when the sentinel
// value is read.
// ------------------------------------------------------------------------
void LoadArray(int A[], int CAP, int & N, int Sentinel, string Prompt)
{
int k;
for(k=0;k<=N;k++)
{
do
{
cout << Prompt;
cin >> A[k];
N = k;
} while(A[k] != Sentinel && k < CAP );
}
cout