Yes/No Statement

I want to make a program which can ask the user YES/NO answer and if YES then the program continues otherwise stop. i have made the program but doing some mistake..

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
 void main()
{
	
		char response;
		int n1, n2;

		for(;;)
		{
		cout<<"Do you want to enter more: (Y/N)";
			cin>>response;

			switch(response)
			{
			case 'Y': 
				cout<<"enter number 1:"<<endl;
				cin>>n1;
				cout<<"enter number 2:"<<endl;
				cin>>n2;
				cout<<"the sum is:"<<n1+n2<<endl;

				break;
			
			case 'N':
				break;
			}
			
		}
				

		
system("pause");
}
The break statements that are there just exit the switch statement.
If they've entered N, you also want to break out of the for loop.

Are they going to do at least one set of number entries? You could use a do .. while loop - and loop while their response is yes. Also - I might convert the case of their Y/N input so the program recognizes both n and N, y and Y.
Topic archived. No new replies allowed.