Thread: storing data into an array

Threaded View

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

    storing data into an array

    I want to store 15 names in an array! but it doesn't seem working correctly... anyone can figure it out ?

    The problem:
    Every time I promote the program to enter a name it will only be stored in the first position in the array. For example, when I promote the program to enter 3 names then print them.. the program will only prints the last input, unlike what it supposed to do and print all inputs

    Code:
    #include <iostream>
    using namespace std;
    
    class healthClubMaintain{
    
    private:
    	 string Al[15];
    	 string Al2[15];
    	 	 
    	 int counter,i,s;
    	
    	int classCleintName;
    	int classClientIDNumber;
    public:
    	void addClient(string);
    	void printClient();
    
    };
    
    
    void healthClubMaintain::addClient(string clientName){
    	counter=0;
    	
    	if (counter ==15){
    		cout << " STOP!";
    
    	}
    	else{
    		Al[counter]=clientName;
    		counter++;
    	}
    		
    
    }
    
    void healthClubMaintain::printClient(){
    	
    		cout<<Al[0];
    		cout <<Al[1];
    }
    
    
    
    
    int main(){
    
    int number,loop=0;
    int clientIDNumber,programNumber,approvalIDNumber,clientIDA,programNumberA;
    string clientName,programName,approvalName;
    healthClubMaintain Club;
    
    while ( loop==0){
    
    	cout<< "Select one of the following option:"<<endl;
    	cout<< "(1) Add a new client to the program"<<endl;
    	cout<< "(2) print"<<endl;
    
    	cin >> number;
    
    
    if ( number ==1 ){
    	cout << "Insert the client's name" << endl;
    	cin >> clientName;
    //	cout << "Insert a new ID" << endl;
    //	cin >>clientIDNumber;
    	Club.addClient(clientName);
    }
    
    if ( number == 2){
    	 Club.printClient();
    }
    
    }
    
    }
    Last edited by aama100; 02-20-2008 at 05:44 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. Bitmasking Problem
    By mike_g in forum C++ Programming
    Replies: 13
    Last Post: 11-08-2007, 12:24 AM
  3. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM
  4. How to complete program. Any probs now?
    By stehigs321 in forum C Programming
    Replies: 7
    Last Post: 11-19-2003, 04:03 PM
  5. C diamonds and perls :°)
    By Carlos in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 05-16-2003, 10:19 PM