do while

For my code I am able to compile but when I run the program it goes through my code once and it will let me run the program again. it will display this but it will skip this question the next one and it will let me answer the one after that.

1
2
3
4
5
6
  cout << "Would you like to enter the information of a new diver?\n";
	cout << "Enter 'y' for yes or an 'n' for no.\n";
	cin >> answer;
	cout << endl;
	
  }while (answer = 'y');

Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
int main()
{
	char choice;

	do
	{
		cout << "\nThis menu. Continue? (Y/N)\n";
		
		cin >> choice;
	}while((choice == 'Y') || (choice == 'y'));

	return 0;
}


Try this.

Notice that the char choice variable is created outside the scope of the loop, as the while condition is outside as well. If the char choice variable is instantiated on the inside, something is going to go wrong, 'cause the while condition isn't going to see inside.

The problem you're having is the use of operators.

I'm a new C++ programmer as well. 2nd year student. Anywaaaaaaaaaay... Make sure you remember to include using namespace std;
and your #include statements.

I often forgot those. :(
Last edited on
Topic archived. No new replies allowed.