Thread: Creating an Id # from first name last name and counter

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    5

    Creating an Id # from first name last name and counter

    I need to use the first character from a first name and the first character from the last name and the counter number to create a student id. This is like BS-1. It must be used in several functions and different for each student. I know how to display it by using the cout<<fname[0]<<lname[0]<<"-"<<counter. I just don't know how to store this info into a variable because of the different data types.

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    25
    how about.....

    Code:
    #include<iostream.h>
    #include<stdio.h>		
    
    
    void main( void )
    {
    
    		char lname[] = "lastname";
    		char fname[] = "firstname";
    		int counter = 1;
    		char id[10] = "";
    		
    		//format the id
    		sprintf(id, "%c%c-%d", fname[0], lname[0], counter);
    		
    		cout << id << endl; 
    }
    inZane
    --true programmer's don't comment--
    --programmer wannabes complain about it--

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    5

    Student ID for class lab

    Thank you very much for your help. At first I had a problem but I went back and systematically recreated my program and got the "bugs" out.

    Your answer was so clear and easy to follow. Thanks again.

Popular pages Recent additions subscribe to a feed