永发信息网

C++代码,编译没问题,但是输入信息后程序崩溃,是哪里的错误

答案:1  悬赏:50  手机版
解决时间 2021-02-16 00:45
  • 提问者网友:人生佛魔见
  • 2021-02-15 13:05
#include
#include
using namespace std;
struct subscriber
{
char name[20];
double money;
};
int main()
{
int people,count1,count2;
cout<<"请输入捐献者数目:";
cin>>people;
subscriber shuzu[people];
cout<<"请输入捐款者信息(姓名及其款项):\n例如: 小明 5000\n";
for(int i=0;i {
cout<<"#"< cin>>shuzu[i].name>>shuzu[i].money;
if(shuzu[i].money>10000)
count1++;
else
count2++;
}
subscriber duhao[count1];
subscriber pingming[count2];
for(int a=0;a {
int b=0;
int c=0;
if(shuzu[a].money>10000)
{strcpy(duhao[b].name,shuzu[a].name);
duhao[b].money=shuzu[a].money;
b++;}
else
{strcpy(pingming[c].name,shuzu[a].name);
pingming[c].money=shuzu[a].money;
c++;}
}
cout<<"\n\nGrand Patrons: \n";
if (count1!=0)
{
for(int i=0;i cout< }
else
cout<<"none!"<
cout<<"\nPatrons: \n";
if (count2!=0)
{
for(int i=0;i cout< }
else
cout<<"none!"< system("pasue");
return 0;
}
最佳答案
  • 五星知识达人网友:怀裏藏嬌
  • 2021-02-15 14:23
你这代码编译也能通过?

subscriber shuzu[people];

数组元素的个数要事先定义,不能靠输入的,要不然你就new出来
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯