468,290 Members | 1,895 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,290 developers. It's quick & easy.

string

16
Hi,i am currently taking c++ and i'm having a problem with the assignment.The assignment is when a user enter the first name of an employee, the id is created by taking the first character of the first name and followed by number.
Does anyone have any ideas?
Nov 22 '06 #1
3 864
sivadhas2006
142 100+
Hi,

This may satisfy your need.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream.h>
  2. #include <time.h>
  3. #include <stdlib.h>
  4.  
  5. int main()
  6. {
  7.    char
  8.       szEmpName[30],
  9.       szEmpID[35];
  10.  
  11.    // get the employee name.
  12.    cout << "Enter the employee name :";
  13.    cin >> szEmpName;
  14.  
  15.    /* Seed the random-number generator with current time so that
  16.     * the numbers will be different every time we run.
  17.     */
  18.    srand( (unsigned)time( NULL ) );
  19.  
  20.    // create a employee id.
  21.    sprintf(szEmpID, "%c%1d", szEmpName[0], rand());
  22.  
  23.    // print the employee id.
  24.    cout << "The employee id is :" << szEmpID;
  25.  
  26.    return 0;
  27. }
  28.  
  29.  
Regards,
M.Sivadhas.
Nov 22 '06 #2
selam
16
Hi,

This may satisfy your need.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream.h>
  2. #include <time.h>
  3. #include <stdlib.h>
  4.  
  5. int main()
  6. {
  7.    char
  8.       szEmpName[30],
  9.       szEmpID[35];
  10.  
  11.    // get the employee name.
  12.    cout << "Enter the employee name :";
  13.    cin >> szEmpName;
  14.  
  15.    /* Seed the random-number generator with current time so that
  16.     * the numbers will be different every time we run.
  17.     */
  18.    srand( (unsigned)time( NULL ) );
  19.  
  20.    // create a employee id.
  21.    sprintf(szEmpID, "%c%1d", szEmpName[0], rand());
  22.  
  23.    // print the employee id.
  24.    cout << "The employee id is :" << szEmpID;
  25.  
  26.    return 0;
  27. }
  28.  
  29.  
Regards,
M.Sivadhas.
It is really greate code.But there is one problem.How can i write it as a function.What values does it accept from the main function.And the id is not generated randomly the user suppose to enter the id like 001 and like that and also when the user enter the id it checks wheather he is the first one in that alphabet or not.
Nov 22 '06 #3
sivadhas2006
142 100+
Hi,

I think to do that you need to store the user name and id in the file right?

Regards,
M.Sivadhas.
Nov 22 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

16 posts views Thread by Krakatioison | last post: by
5 posts views Thread by Stu Cazzo | last post: by
9 posts views Thread by John F Dutcher | last post: by
10 posts views Thread by Angus Leeming | last post: by
2 posts views Thread by Andrew | last post: by
29 posts views Thread by zoro | last post: by
2 posts views Thread by Badass Scotsman | last post: by
15 posts views Thread by morleyc | last post: by
2 posts views Thread by MrBee | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.