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.
#include<cstdlib>
#include<iostream>
#include<fstream>
#include<string.h>
usingnamespace 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.