Can someone please tell me what I'm doing wrong , cause this loop will not terminate, even if I enter the sentinal character. I really can't figure out why I'm wrong.
Int main()
{
Int maxVal = 10;
Char characters[maxVal];
Int I = 0;
Do
{
Cout<<"enter character";
Cin<<characters[i];
I++;
I'm not that good with programming either, but what does characters[i] refer to? You have capital and lower case I and i. You are also capitalizing a bunch of stuff that shouldn't be, your stream operators are wrong, so I'm not even sure how it runs. 'i' was never initialized, and you never change the value of characters[i], so the while is never satisfied, I think. Wouldn't you rather use a for loop like this?
you should use a while loop, while cin is reading a char and its not x then add one to int I. also all variable types should be lower case, and variables
are case sensitive. lastly, if you make the size of characters[10] you can only enter 10 values in the array, use a vector if you dont know how many chars will be entered.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
int main (){
unsignedint maxVal = 10;
char characters[maxVal];
int I = 0;
cout << "enter character" << endl;
while(cin >> characters[I] && characters[I] != 'x')
++I;
return 0;
}
Oooh Thank you its works :D. Jidder is right. And the the upper case lower case "i" is not the problem. I know c++ is case sensitive.. I just typed the code using my cellphone , that's why. I'm supposed to use a do..while loop.. Now I had the same problem using a switch which was nested inside a do..while loop. Since I'm not using arrays.. What will the condition be inside the while? I'm supposed to enter char 'X' to terminate.