Problem with do and while loops

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>

using namespace 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
Last edited on
Line 8:
You name your variable character but have it as type int?

Line 14:
A single variable can't hold two different values at one instance.
ah ok, yeh that was stupid of me. I understand the problem now. I keep making these stupid mistakes, hopefully will be past that soon
Topic archived. No new replies allowed.