Apr 15, 2014 at 9:48pm
how can i stop a loop if
continue == 'n' || coninue == 'N'
i need to keep my
but
cin.ignore
my
.
Last edited on Apr 17, 2014 at 6:57pm
Apr 15, 2014 at 11:34pm
while (Continue != 'n' && Continue != 'N');
Apr 16, 2014 at 5:29am
You can stop the loop by using any other character other n or N as input
Apr 17, 2014 at 6:58pm
here is my code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#include <iostream>
using namespace std;
const int Size = 20;
int main()
{
int T[20];
int A[20];
char Continue;
int i = 0, Digit, k;
do
{
for (i = 0; i < Size; i++)
{
A[i]=0;
T[i]=0;
}
i = 0;
cout << "\n\nPlease enter first number --> ";
Digit = cin.get ();
while (Digit != '\n' && i < Size)
{
T[i] = Digit - '0';
++i;
Digit = cin.get();
}
for ( k = Size - 1, --i; i >= 0 ; --i, --k)
{
A[k] = T[i];
}
cout << endl;
for (i = 0; i < Size; i++)
{
cout << A[i];
}
cin.ignore();
cout << "\n\nContinue? Y or N ";
cin >> Continue;
}
while ( Continue != 'n' || Continue != 'N');
}
|
my
however, deletes even my Continue character and will continuously loop even when i put in 'N'
Last edited on Apr 17, 2014 at 6:58pm
Apr 17, 2014 at 8:53pm
The ignore should occur after line 43.
The condition on line 46 is not correct. It can never be false.
When
Continue is
'n'
the condition looks like this:
1 2
|
while ( 'n' != 'n' || 'n' != 'N' ) // which simplifies to:
while ( false || true ) // which, according to truth tables for logical or, is true
|
I'm sure you could do the same substitution for
'N'
.
Last edited on Apr 17, 2014 at 8:54pm