Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

switch cases not working

$
0
0
Hello everyone

I write this C++ code about (binary search tree structure)

I wrote header file and implementation file and I sure it's write
the problem with switch ,,, cases doesn't work .. only default one

Tree my_tree;
	char choice[2];
	char x;
	char y;

	my_tree.insert('A');
	my_tree.insert('B');
	my_tree.insert('F');
	my_tree.insert('G');
	my_tree.insert('T');
	my_tree.insert('R');
	my_tree.insert('M');
	my_tree.insert('K');
	my_tree.insert('X');



	do{
    cout<<"Please enter a chrecter to choose from the list: "<<endl;
	cout<<"'I' to insert a character."<<endl;
	cout<<"'S' to search for a character"<<endl;
	cout<<"'TI' for inorder traversal"<<endl;
	cout<<"'TP' for inorder traversal"<<endl;
	cout<<"'QU' to quit"<<endl;

		gets (choice);

		switch (choice[2]){

		case 'I': case 'i':
			cout<<"Enter a charecter to insert: ";
	        x=getchar();
	        my_tree.insert(x);
		break;

		case 'S': case 's':
			cout<<"Enter a charecter to search: ";
	        y=getchar();
	       if(my_tree.search(y))
			   cout<<"The charecter is exist";
		   else 
		       cout<<"The charecter isn't exist";
		break;

		case 'TI': case 'ti':
			inorderPrint(my_tree);
		break;

		case 'TP': case 'tp':
		    preorderPrint(my_tree);
		break;

		default:
			cout<<"Invalid choice"<<endl<<endl;
		
	}// end switch
	}while (choice[2] != 'qu' || choice[2] !='QU');



and the output like that
http://

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>