10 Digit unique number

Hello to everyone!
I would like to receive some help of the c++ forum.
Here is the task: I have to create a 10 digit unique number for each person born from 1959 to 1999 using a special algorithm.
So far i got this :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* Program for creating unique 10 digit number for prople joining the group 
The number will consist of 9 digits and a control number
Ex.: Person with 8601305762 will be born on 1986 (first 2 digits show the year),
Janurary (01 - first month), 30- day of month , 576 - first male  person registered in region 
( the region range will be from 576 to 601 , first male person - 576, second male 578 , etc
Female clients have all the odd numbers in the range;
The control number algorithm is this : first digit *2 + second *4+third *8 +
four dig * 5, fifth * 10 + sixth * 9 + seventh * 7 + eighth * 3 + ninth * 6 % 11.If number is
10 - the control number is 0; 
*/

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
inline void keep_window_open () {char ch; cin >> ch;}

int main () {
	string year = "";
	cout << "enter the last 2 digits fo the year of birth:\n" ; cin >> year; 
	string month ="";
	cout << "enter the month of birth in two-digit format:\n"; cin >> month;
	string day = "";
	cout << "enter the day of birth in two-digit format:\n" ; cin >> day;
	
	cout << year+month+day+"5762\n";
	
	keep_window_open();

	return 0;
}  

Well this is far away from the task but i was thinking to modify it but maybe i will have to start from scratch. I`m a beginner and i would like if somebody can assist me giving some ideas how to modify , or from where to start.
Thanks in Advance.
PS: according to the statistics maximum of 26 people were born in my area.
Last edited on
Yo,
For the 3-digit number from 576 to 601 you might get in trouble: if more than 13 females or more than 13 males are born on one day, you'll have a number larger than 601.
As for assisting: you need to know whether the person is male or female.
1
2
bool female_male;
cout << "Are you female or male? 0=female, 1=male\n"; cin >> female_male;

You need two integers to keep track of females and males:
1
2
int femalecounter = 565;
int malecounter = 564;

And you need an if-statement:
1
2
if (female_male == 0) femalecounter+2;
if (female_male == 1) malecounter+2;

This only makes sense if you put everything in a loop, except the initializations (string year; -- int malecounter;). You can use a for loop, for example.
Concerning the control number, consider string function at:
1
2
3
string year = 08;
char firstdigitchar = year.at(0);
char seconddigitchar = year.at(1);

This gets you the first and second digit.
Another thing you would want to do is convert the strings and chars to signed integers. Google "string char integer" and you might find something useful. You need to do conversions in order to be able to calculate using the value in chars and strings. E.g,
1
2
int firstdigit = (int) firstdigitchar - '0'; // substract the char value of 0 to get the int
firstdigit = firstdigit*2;
Hope this gets you on the way!
Last edited on
Topic archived. No new replies allowed.