Thread: Premature stoppage type thingy with tags

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    3

    Premature stoppage type thingy with tags

    this is my program (isn't it nice ) the problem i'm having is that the program stops after "search" is selected but there should be another option.....does anyone know why?
    and i've been told i should apologise for my earlier
    thread.


    Code:
    #include <iostream.h>
    #include <fstream.h>
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    
    char choice,type,choose,decide;
    int e,s,c,p,a;
    
    //-----------------------------------
    //base and derived classes
    class books {
     public:
    struct database {
        char title[256];
        char author[256];
    	char isbn[11];
    	char publishername[256];
    	char cdrom[4];
    	char yearofpub[5];
    	char price[5];
      }np[20];   // end of struct
    //..........................
      void search(int);
      void enter(int);
      void remove(void);
      void first(void);
      void author(void);
      void pub(void);
    
      
    };
    //------------------------------------
    
    
    
    class store: public books{
    	public:
    	void save(void);
    	void load(void);
    };
    	
    //------------------------------------
    int main(int) {
      books bdata; 
      store storage;
      storage.first();
      
      return(0);
      };
      
    //------------------------------------
    
    void books::first(void) {
    cout<<"-----------------------------------------------------------\n";
    cout<<"|                                                         |\n";
    cout<<"|                Welcome to the Book                      |\n";
    cout<<"|                      Database                           |\n";
    cout<<"|                                                         |\n";
    cout<<"-----------------------------------------------------------\n\n\n\n";
    
    cout<<" What would you like to do? \n";
    cout<<" Select:\n\n";
    cout<<" 1			To add a book\n";
    cout<<" 2			To search for a book\n";
    cout<<" 3			To remove a book\n";
    cout<<" 4			Clear book database\n";
    cout<<" 5			Show all books\n";
    choice=getchar();
    choice=toupper(choice);
    switch(choice) {
    
    	case '1': {
    		cout<<"you selected 'Add'\n";
    		enter(e);
    		break;}
    		
    	case '2': {
    		cout<<"you selected 'Search'\n";
    		search(s);
    		break;}
    		
    		
    	case '3': {
    		cout<<"you selected 'Remove'\n";
    		break;}	   
    		
    	
    	case '4': {
    		cout<<"you selected 'Clear'\n";
    		break;}
    		
    	case '5': {
    		cout<<"you selected 'show all'\n";
    		break;}
    
    };
    }; 
      
    //---------------------------------------
    //member functions
    		void books::enter(int e) {
    		
    			cout<<"Enter the book title: ";
    			cin>>(np[e].title);
    			cout<<"Enter the author: ";
    			cin>>(np[e].author);
    			cout<<"Enter the ISBN number: ";
    			cin>>(np[e].isbn);
    			cout<<"Enter the publisher name: ";
    			cin>>(np[e].publishername);
    			cout<<"Is there a CDROM included (yes or no): ";
    			cin>>(np[e].cdrom);
    			cout<<"Year published: ";
    			cin>>(np[e].yearofpub);
    			cout<<"Enter price - exclude  sign: ";
    			cin>>(np[e].price);
    	
    };
    
    //------------------------------------------		
    	   
    		void books::search(int s) {
    cout<<"-----------------------------------------------------------\n";
    cout<<"|                                                         |\n";
    cout<<"|                Welcome to the Book                      |\n";
    cout<<"|                      Database                           |\n";
    cout<<"|                                                         |\n";
    cout<<"-----------------------------------------------------------\n\n\n\n";
    
    cout<<" What would you like to search by? \n";
    cout<<" Select:\n\n";
    cout<<" 1			Author.\n";
    cout<<" 2			Publisher\n";
    
    choose=getchar();
    choose=toupper(choose);
    switch(choose) {
    
    	case 'A': {
    		cout<<"you selected 'Search by Author'\n";
    		author();
    		break;}
    		
    	case 'B': {
    		cout<<"you selected 'Search by Publisher'\n";
    		pub();
    		break;}
    
    
    };
    }; 
    
    		void books::author() {
    		
    			cout<<"Enter the book title: ";
    			cin>>(np[a].title);
    			cout<<"Enter the author: ";
    			cin>>(np[a].author);
    			cout<<"Enter the ISBN number: ";
    			cin>>(np[a].isbn);
    			cout<<"Enter the publisher name: ";
    			cin>>(np[a].publishername);
    			cout<<"Is there a CDROM included (yes or no): ";
    			cin>>(np[a].cdrom);
    			cout<<"Year published: ";
    			cin>>(np[a].yearofpub);
    			cout<<"Enter price - exclude  sign: ";
    			cin>>(np[a].price);
    	
    };
    
    		void books::pub() {
    		
    			cout<<"Enter the book title: ";
    			cin>>(np[p].title);
    			cout<<"Enter the author: ";
    			cin>>(np[p].author);
    			cout<<"Enter the ISBN number: ";
    			cin>>(np[p].isbn);
    			cout<<"Enter the publisher name: ";
    			cin>>(np[p].publishername);
    			cout<<"Is there a CDROM included (yes or no): ";
    			cin>>(np[p].cdrom);
    			cout<<"Year published: ";
    			cin>>(np[p].yearofpub);
    			cout<<"Enter price - exclude  sign: ";
    			cin>>(np[p].price);
    	
    };
    Last edited by Salem; 05-16-2004 at 12:23 AM. Reason: changed \ to / in the closing code tag

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    1. If you want to apologize do it somewhere else, this is a programming forum.
    2. Thread titles should be specific; you should try summarize the problem quickly, eg:
    Program flow error; branch is never reached
    3. Use code tags
    4. Read the rules
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > does anyone know why?
    Well your code contains no loops - so you basically get asked just the once.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    i didn't mean for you to say sorry, i was just pointing out that it's much easier for us to help you when we can read your code somewhat Most people will see all of that code all left aligned and just be like "way too much work, not feeling like putting that much effort in to it"

    If you want your question answered and answered fast, put what you know, what you need to know, and the required code that could help solve your problem.

    Just remember that for next time

    -edit-
    and did you read my answer to your problem on the other post?
    Last edited by jverkoey; 05-16-2004 at 12:23 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  2. Little Array Difficulty
    By G4B3 in forum C Programming
    Replies: 16
    Last Post: 03-19-2008, 12:59 AM
  3. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM
  4. odd errors from msvc std library files
    By blight2c in forum C++ Programming
    Replies: 6
    Last Post: 04-30-2002, 12:06 AM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM