I have created a small piece of code to test out do and while. But when i run it, it is not running like it should. When i press in either y or n i believe the program should end but instead it continues to ask the same question, "Do you wish to delete this file" (it also does this when i put in any other character. I am new to coding so any help would be great, thanks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
usingnamespace std;
int main()
{
int character;
do
{
cout << "Do you wish to delete this file?" << endl;
cin >> character;
}
while (character != 'y' && character != 'n');
system("PAUSE");
return 0;
}
EDIT. ok i have worked out one problem, when i remove endl; and put in a character other than y or n it repeats the line just once one. Can someone explain why removing the endl; solved this?
The problem still persists when i enter y or n, i think this may be because i have not written any code for when a y or n is input. can someone confirm this please. thanks