-5
我的代碼有什麼問題。我想添加10次數據並查看詳細信息,但我無法做到。任何人都可以幫助我嗎?不能超過1次C++
#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 to SYSTEM analyze *\n";
cout<<"*******************************************************************************\n\n";
cout<<" Welcome to SYSTEM analyze \n\n";
cout<<"1.Voter Analysis 1\n2.Voter Details 2\n3.Exit 3\n\n";
cout<<"*******************************************************************************\n";
cout<<"Please enter your 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";
}
}
你在'for'循環中沒有做任何事情。 – Barmar
你的變量對每個函數都是局部的。當您在'analytics'中設置'voterid'時,它將不會在'details'中顯示。您必須將它們放入從一個函數返回並傳遞給另一個函數的結構中,或者使用全局變量。 – Barmar
如果你想添加多個數據,你需要創建一個包含所有這些數據的結構數組。你真的錯過了一些基本概念,我不認爲SO是合適的論壇,試圖教你編程的基礎知識。 – Barmar