do, whilel error

This is a discussion on do, whilel error within the C++ Programming forums, part of the General Programming Boards category; i seem to have an error in my do while loop and i cannnot see where i have gone wrong. ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    7

    do, whilel error

    i seem to have an error in my do while loop and i cannnot see where i have gone wrong. Any help would be very much appreciated. Here is the part of my code affected,
    Code:
    do {
       db.insertionSort();                                     // insertion-sort them   
       
     
       
        cout << "\nSelect an option:\n\n";		     // menu display options
           cout << "   1 Add a new CD.\n";
           cout << "   2 Display all CDs.\n";
           cout << "   3 Search CDs by Artist.\n";
    	   cout << "   4 Delete CD.\n";
           cout << "   5 To Quit Program.\n";
           cin >> menuValue;
    	   
    
    if( menuValue == 1 )        // the actual menu
    	   cout << "\nEnter Artist:\n"; cin >> artist; 
    	   cout << "Enter Title:\n"; cin >> title;
    	   cout << "Enter Genre:\n"; cin >> genre;
    	   cout << "Enter Year:\n"; cin >> year;
    	   db.insert (artist, title, genre, year );
    	   }
    	else if ( menuValue == 2 ){
    			cout << "List of CD's in Library: \n\n" << endl;
      		    db.display();                				 // display all records
    			}
    		else if (menuValue == 3){
    		 	cout <<"Enter Artist search: ";
    			db.searchArtist();			//display selected artist
    			}
    				else if(menuValue == 4 ){
    				db.deleteCompactDisc();          // delete selected person
      				cout << "\nCD's in Library after deletion:\n\n" << endl;
      			    db.display();                 		// display them again
    				}
    					else {
    					menuValue == 5;
    					exit(1);
    					}
    		
    }while(menuValue !=1 && menuValue !=2 && menuValue != 3 && menuValue !=4 && menuValue != 5){
    		cout << "Select a number from 1 to 5";
    		cin.clear();
    		cin.ignore(256, '\n');
    		}
    return 0;
    }
    ,

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    If you're talking about a compile error it's propably the missing semicolon after the condition
    Code:
    }while(menuValue !=1 && menuValue !=2 && menuValue != 3 && menuValue !=4 && menuValue != 5); // <<==
    Kurt

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,788
    It would help if you actually posted the error, but maybe...

    Code:
    do {
        ...		
    }while(menuValue !=1 && menuValue !=2 && menuValue != 3 && menuValue !=4 && menuValue != 5){
        ...
    }
    Is this a do/while or a while/do or some strange combination you're attempting to concoct?


    Code:
    if( menuValue == 1 )        // the actual menu
    	   cout << "\nEnter Artist:\n"; cin >> artist; 
    	   cout << "Enter Title:\n"; cin >> title;
    	   cout << "Enter Genre:\n"; cin >> genre;
    	   cout << "Enter Year:\n"; cin >> year;
    	   db.insert (artist, title, genre, year );
    	   }
    Missing an opening brace '{' in there somewhere?
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    31
    <- slowpoke, read post above (edit)

    It is easier to read the code if you do some consistent indentation:

    Code:
    do {
    	db.insertionSort();                                     // insertion-sort them   
    
    	cout << "\nSelect an option:\n\n";     // menu display options
    	cout << "   1 Add a new CD.\n";
    	cout << "   2 Display all CDs.\n";
    	cout << "   3 Search CDs by Artist.\n";
    	cout << "   4 Delete CD.\n";
    	cout << "   5 To Quit Program.\n";
    	cin >> menuValue;
    
    
    	if( menuValue == 1 )        // the actual menu
    		cout << "\nEnter Artist:\n"; cin >> artist; 
    
    	cout << "Enter Title:\n"; cin >> title;
    	cout << "Enter Genre:\n"; cin >> genre;
    	cout << "Enter Year:\n"; cin >> year;
    
    	db.insert (artist, title, genre, year );
    }
    
    else if ( menuValue == 2 ){
    	cout << "List of CD's in Library: \n\n" << endl;
    	db.display();                 // display all records
    }
    else if (menuValue == 3){
    	cout <<"Enter Artist search: ";
    	db.searchArtist();//display selected artist
    }
    else if(menuValue == 4 ){
    	db.deleteCompactDisc();          // delete selected person
    	cout << "\nCD's in Library after deletion:\n\n" << endl;
    	db.display();                 // display them again
    }
    else {
    	menuValue == 5;
    	exit(1);
    }
    
    }while(menuValue !=1 && menuValue !=2 && menuValue != 3 && menuValue !=4 && menuValue != 5){
    	cout << "Select a number from 1 to 5";
    	cin.clear();
    	cin.ignore(256, '\n');
    }
    return 0;
    }
    As you might have noticed, there is a '{' missing after 'if( menuValue == 1 )', also the code from your while(..) at the bottom and down doesn't do what you think it does.
    Last edited by edoceo; 03-18-2009 at 01:20 PM. Reason: <- slowpoke (bathroombreak while writing post = bad)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 12:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21