Thread: Problem in the menu

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    58

    Problem in the menu

    My program compiles and works perfectly but the the menu doesn't work? I couldn't know what's the problem with it ?


    Here is my menu
    Code:
    	int tester;
    	while ( (tester>=1)&&(tester<4) )
    	{  		
    			cout << "select one of these options\n";
     			cout << "(1) Insert a new code\n";
     			cout << "(2) Print the data\n";
    			cout << "(3) Exit the program\n";
    
    			cin >> tester;
    			
    			if(tester==1){
          		                cout << "Insert a code of 12 characters:";
    				cin >> codeNumber;
    				length = codeNumber.length();
    				rect.set_values (length,codeNumber);
    				rect.check();
    		   }
    			
    			if (tester==2){
    				cout << "Insert a code of 12 characters:";
    				cin >> codeNumber;
    				length = codeNumber.length();
    				rect.set_values (length,codeNumber);
    				rect.check();
    				rect.printCode(length);
    			}
    			
    			if (tester==3){
    				break;
    			}
    			else{
    				cout << "ERROR!!! You must choose one of the following options 1 to 4";

    Code:
    
    #include <iostream>
    using namespace std;
    
    // declaring a class
    class CRectangle 
    {
    	//Three methods in use
    	public:
        
        	void set_values(int, string);
    		string check();
    	 	void printCode(int);
    
    	private:
    	
    		int x,flag,flag1,flag2,flag3,counter,counter1,counter2,counter4;
    		string y,mystr;
    		size_t found,found1,found2,found3,found4,found5,found6,found7,found8,found9,found10,found11;	
    		string billy[];		
    		
    };
    
    
    //printing an array
    void CRectangle::printCode (int a)
    {
    	counter4=0;
    	while(counter <= a)
    	{
    		cout << billy[counter]<<endl;
    	}
    }
    
    //set the values 
    void CRectangle::set_values (int a, string b)
    {
      	x = a;
      	y = b;
    }
    
    //check the four conditions
    string CRectangle::check()
    {
       found = y.find('4'); 
    	found1 = y.find('5'); 
    	found2 = y.find('8'); 
    	found3 = y.find('9'); 
    	found4 = y.find('A'); 
    	found5 = y.find('L'); 
    	found6 = y.find('P'); 
    	found7 = y.find('R');
    	found8 = y.find('T'); 
    	found9 = y.find('V'); 
    	found10 = y.find('W'); 
    	found11 = y.find('X');
    	flag =0;
    	flag1=0;
    	flag2=0;
    	flag3=0;
    	counter=0;
    	counter1=4;
    	counter2=8;
    	mystr = y;
    	billy[12];
    	if(x != 12)
    	{
    		cout << "false"<< endl;
    	}
    		
    	else if ((found==string::npos)||(found1==string::npos))
    				cout << "Error: The digits 4 and 5 must appear at least once."<<endl;
    		  else if ((found2==string::npos)&&(found3==string::npos))
    			    	cout << "Error: Either the digit 8 and 9 must appear at least once." << endl;
    				 else  					
    						while(counter<4)
    						{
    							if ( (found4!=string::npos) || (found5!=string::npos) || (found6!=string::npos) || (found7!=string::npos)|| (found8!=string::npos) || (found9!=string::npos) || (found10!=string::npos)||(found1!=string::npos))
    							{
    								flag=1;
    								break;
    							}
    							counter++;	
    	
    						}
    								  			
    						if(flag){
    							while(counter1<8)
    							{
    								if ( (found4!=string::npos) || (found5!=string::npos) || (found6!=string::npos) || (found7!=string::npos)|| (found8!=string::npos) || (found9!=string::npos) || (found10!=string::npos)||(found11!=string::npos))
    								{
    									flag1=1;
    									break;		
    								}							
    							
    								counter1++;
    							}
    							if(flag1){
    								while(counter2<12)
    								{
    									if ( (found4!=string::npos) || (found5!=string::npos) || (found6!=string::npos) || (found7!=string::npos)|| (found8!=string::npos) || (found9!=string::npos) || (found10!=string::npos)||(found11!=string::npos))
    									{
    										flag2=1;
    										break;
    
    									}							
    
    									counter2++;
    								}
    								if(flag2){
    									while(counter<12)
    									{
    										if ( (mystr[counter] == 'Q') || (mystr[counter] == 'E') || (mystr[counter] == 'Y') || (mystr[counter] == 'U') || (mystr[counter] == 'I') || (mystr[counter] == 'O')||(mystr[counter] == 'S')||(mystr[counter] == 'D')||(mystr[counter] == 'F')||(mystr[counter] == 'G')||(mystr[counter] == 'H')||(mystr[counter] == 'J')||(mystr[counter] == 'K')||(mystr[counter] == 'Z')||(mystr[counter] == 'C')||(mystr[counter] == 'B')||(mystr[counter] == 'N')||(mystr[counter] == 'M')||(mystr[counter] == 'q')||(mystr[counter] == 'w')||(mystr[counter] == 'e')||(mystr[counter] == 'r') || (mystr[counter] == 't') || (mystr[counter] == 'y') || (mystr[counter] == 'u') || (mystr[counter] == 'i') || (mystr[counter] == 'o') || (mystr[counter] == 'p') || (mystr[counter] == 'a') || (mystr[counter] == 's') || (mystr[counter] == 'd') || (mystr[counter] == 'f') || (mystr[counter] == 'g') || (mystr[counter] == 'h') || (mystr[counter] == 'j') || (mystr[counter] == 'k') || (mystr[counter] == 'l') || (mystr[counter] == 'z') || (mystr[counter] == 'x') || (mystr[counter] == 'c') || (mystr[counter] == 'v') || (mystr[counter] == 'b') || (mystr[counter] == 'n') || (mystr[counter] == 'm') )
    										{
    												flag3=1;
    												break;
    										}
    										counter++;
    									}
    
    									   
    								}				
    						   }
    						}	  
    			
    if(flag3)
    {
    		cout << "You are mising one or more of the following:\n";
    		cout << "   1. The only valid letters are A,L,P,R,T,V,W, and X.\n";
    		cout << "   2. Each four-character subsquence (1-4, 5-8, 9-12) must contain at least one digit and at least one letter.\n";
    		cout << "  \n"<<endl;
    }
    else
    {
    	cout << "The code is correct:" << y <<endl;
    	while(counter<12)
    	{
    			billy[counter]=mystr[counter];
    			counter++;
    	}
    }
    								
    	return  y;
    }
    
    
    int main () {
      	
    	int length;
    	string codeNumber;
            string mystr = codeNumber;
    	CRectangle rect;
    
    	int tester;
    	while ( (tester>=1)&&(tester<4) )
    	{  		
    			cout << "select one of these options\n";
     			cout << "(1) Insert a new code\n";
     			cout << "(2) Print the data\n";
    			cout << "(3) Exit the program\n";
    
    			cin >> tester;
    			
    			if(tester==1){
          		cout << "Insert a code of 12 characters:";
    				cin >> codeNumber;
    				length = codeNumber.length();
    				rect.set_values (length,codeNumber);
    				rect.check();
    		   }
    			
    			if (tester==2){
    				cout << "Insert a code of 12 characters:";
    				cin >> codeNumber;
    				length = codeNumber.length();
    				rect.set_values (length,codeNumber);
    				rect.check();
    				rect.printCode(length);
    			}
    			
    			if (tester==3){
    				break;
    			}
    			else{
    				cout << "ERROR!!! You must choose one of the following options 1 to 4";
    			}
       }
       	return 0;
    }
    Last edited by aama100; 02-05-2008 at 04:59 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  2. Simple Menu Problem
    By DanC in forum C++ Programming
    Replies: 4
    Last Post: 03-15-2006, 01:33 PM
  3. Problem with Mouse Over Menu!!! HELP!!!
    By SweeLeen in forum C++ Programming
    Replies: 3
    Last Post: 02-09-2006, 02:10 AM
  4. Window - Menu problem...
    By FromHolland in forum Windows Programming
    Replies: 1
    Last Post: 02-26-2004, 03:49 PM
  5. MDI and MENU Problem
    By Marc in forum Windows Programming
    Replies: 3
    Last Post: 02-21-2004, 06:59 PM