Hi!

How do i repeat my program?
if i press Y or N in loops infinitely

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
33
34
35
36
37
38
39
40
41
42
43
44
45
 #include <iostream>
using namespace std;

int main(){

	int choice, num;
	char again;

		do{
	cout << "MENU" << endl;
	cout << "[1] Double" << endl;
	cout << "[2] Half" << endl;
	cout << "[3] Do Nothing" << endl;
	cout << "Type your choice: ";
	cin >> choice;
	cout << endl;
	
		if (choice == 1){
			cout << "Type a number: ";
			cin >> num;
			
			cout << "Double of " << num << " is " << num*2 << endl;
				cout<<"Again? (Y/N): ";
				cin>>choice;
		}
		else
			if(choice == 2){
				cout << "Type a number: ";
				cin >> num;
				cout << "Half of " << num << " is " << num/2 << endl;
				cout<<"Again? (Y/N): ";
				cin>>choice;
	}
		else 
				cout << "Type a number: ";
				cin >> num;	
				cout << "Given number is " << num << endl;
				cout<<"Again? (Y/N): ";
				cin>>choice;

}
while(toupper (again) != 'N');
	
return 0;
}
You are checking against again but you don't use again in your program.

http://cpp.sh/7gn6
Topic archived. No new replies allowed.