Electronic voting

Hello everyone. I have to do a program for electronic voting. It supposed to have a file data where it should be this information of people: name, age and place of birth. Then when the user goes to the program he will have to introduce his id card and if he's older than 18 he'll be able to vote. I did this code for the data file.

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include<cstdlib>
#include<iostream>
#include<fstream>
#include<string.h>
using namespace std;
void add_info();
void introduce_idcard();
void out();
void menu();
//Global variables
char name[30],place[10];
int age=0;
int main(){
    menu();
    return 0;
}
void menu(){
    int option=0;
    do{
        cout<<"Welcome"<<endl;
        cout<<"1. Add information: "<<endl;
        cout<<"2. Introduce id card: "<<endl;
        cout<<"3. Out"<<endl;
        cout<<"What do you want to do? ";
        cin>>option;
        switch(option){
            case 1:
                add_info();
            break;
            case 2:
                introduce_idcard();
            break;
            case 3:
                out();
            break;
            default:
                cout<<"Incorrect option!"<<endl;
        }
    }while(option!=3);
}
void introduce_idcard(){
    ofstream writing;
    writing.open("data.txt",ios::out|ios::app);
    if(writing.is_open()){
        cout<<"Add name: ";
        cin>>name;
        cout<<"Add place of birth: ";
        cin>>place;
        cout<<"Add age: ";
        cin>>age;
        escritura<<name<<" "<<place<<" "<age<<" "<<endl;
    }else{
        cout<<"Error, file could not open"<<endl;
    }
    writing.close();
}

void add_info(){
    ifstream reading;
    reading.open("data.txt",ios::out|ios::in);
    if(reading.is_open()){
        cout<<"File data.txt"<<endl;        
        do{
        cout<<"________________________________"<<endl;	
            lectura>>name;
            lectura>>place;
            lectura>>age;
            cout<<"Name: "<<name<<endl;
            cout<<"Place of birth: "<<place<<endl;
            cout<<"Age: "<<age<<endl;
        cout<<"________________________________"<<endl;    
        }
		while(!reading.eof());          
    }else{
        cout<<"Error, file could not open"<<endl;
    }
    reading.close();
}

void out(){
    cout<<"Exit"<<endl;
}


My problem is that I don't know how to relate the user's id card to his personal information on the data file. Please help me if you can. Thanks in advance.
Last edited on
Hi,

how to relate the user's id card to his personal information on the data file


maybe you introduce a new parameter ID number which will be unique to each user
Topic archived. No new replies allowed.