Can't inside more than 1 time C++ -
what's wrong code. want add data 10 times , view details, can't it. me this?
#include <iostream.h> #include <conio.h> #include<string.h> void load_menu(void); void analysis(void); void details(void); int main(int argc, char** argv) { load_menu(); return 0; } void load_menu(void) { int choice; while (1) { cout<<"*******************************************************************************\n"; cout<<"* welcome system analyze *\n"; cout<<"*******************************************************************************\n\n"; cout<<" welcome system analyze \n\n"; cout<<"1.voter analysis 1\n2.voter details 2\n3.exit 3\n\n"; cout<<"*******************************************************************************\n"; cout<<"please enter choose : ";cin>>choice; switch(choice) { case 1 : analysis(); break; case 2: details(); break; case 3: cout<<"going out !\n"; exit(1) ; break; default: cout<<"\n\n\n\n\n\n\n"; cout<<"*******************************************************************************\n"; cout<<"* please insert again !! *\n"; cout<<"*******************************************************************************\n\n"; cout<<"\n\n\n\n"; break; } } } void analysis(void) { char voterid[10]; char votername[30]; char voteraddr[30]; char phone[15]; int age; char status[20]; { cout<<"get voterid"; cin>>voterid; cout<<"voter's name"; cin>>votername; cout<<"voter's address"; cin>>voteraddr; cout<<"phone number"; cin>>phone; cout<<"voter's age"; cin>>age; if(age>18) strcpy(status,"eligible"); else strcpy(status,"not eligible"); for(int i=0;i<10;i++); } } void details(void) { char voterid[10]; char votername[30]; char voteraddr[30]; char phone[15]; int age; char status[20]; { cout<<"voter's information\n"; cout<<"--------------------\n"; cout<<"voter id:"<<voterid<<"\n"; cout<<"voter name:"<<votername<<"\n"; cout<<"voter addr:"<<voteraddr<<"\n"; cout<<"phone no:"<<phone<<"\n"; cout<<"voter's age:"<<age<<"\n"; cout<<"status:"<<status<<"\n"; cout<<"-----------------\n"; } }
there lots of mistakes in code:
- all variables voterid[10]; votername[30]; voteraddr[30]; phone[15]; age; status[20] local function
analysis
, functiondetails
. data store in variablesanalysis
function not getting accessed indetails
. so, make variables global. - in
analysis
, have putfor
statement @ wrong place.for
loop not iterating. that's why not able insert data more once. - in
details
, there nofor
loop data array. voterid
array. so, put value in using index - like:voterid[i]
i
index.- you may use
iostream
instead ofiostream.h
in header file.
Comments
Post a Comment