| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4268 人关注过本帖
标题:这段代码有问题吗,在编译的时候会出现崩溃的现象
只看楼主 加入收藏
langmanxiang
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2016-3-24
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:3 
这段代码有问题吗,在编译的时候会出现崩溃的现象
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
struct donation
{
    string name;
    double money;
};

int main ()
{
    int n_of_donation=0;
    cout<<"输入捐款者的数目:\n";
    cin>>n_of_donation;

    donation *list=new donation[n_of_donation];

    for(int i=0;i<n_of_donation;i++)
    {
        cout<<"输入第 "<<i+1<<" 位捐款者的信息:\n";
        cout<<"name:\n";
        cin>>list[i].name;
        cout<<"money:\n";
        cin>>list[i].money;
    }

    int temp=0;
    cout<<"重要捐款人:"<<endl;
    for(int m=0;m<n_of_donation;m++)
    {
        if(list[m].money>10000)
        {
            cout<<list[m].name<<"     "<<list[m].money<<endl;
            temp++;
        }
    }
    if(temp==0)
        cout<<"None.\n";

    temp=0;
    cout<<"捐款人: "<<endl;
    for(int o=0;o<n_of_donation;o++)
    {
        if(list[o].money<=10000)
        {
            cout<<list[o].name<<"     "<<list[o].money<<endl;
            temp++;
        }
    }
    if(temp==0)
        cout<<"None!\n";

    delete list;
    getchar();
    getchar();
    return 0;

}
搜索更多相关主题的帖子: include double money 信息 
2016-04-05 08:54
wengbin
Rank: 10Rank: 10Rank: 10
来 自:陕西西安
等 级:贵宾
威 望:19
帖 子:370
专家分:1846
注 册:2015-5-8
收藏
得分:4 
错误信息呢?我编译时提示getchar();不能用,我就用cin.get()代替了,之后没有问题
2016-04-05 10:44
醒山
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:9
帖 子:463
专家分:2071
注 册:2015-5-25
收藏
得分:1 
我运行的没问题啊
2016-04-05 12:22
hjx1120
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:李掌柜
等 级:贵宾
威 望:41
帖 子:1314
专家分:6927
注 册:2008-1-3
收藏
得分:15 
程序代码:
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
struct donation
{
    string name;
    double money;
};

int main ()
{
    int n_of_donation=0;
    cout<<"输入捐款者的数目:\n";
    cin>>n_of_donation;

    donation *list=new donation[n_of_donation];

    for(int i=0;i<n_of_donation;i++)
    {
        cout<<"输入第 "<<i+1<<" 位捐款者的信息:\n";
        cout<<"name:\n";
        cin>>list[i].name;
        cout<<"money:\n";
        cin>>list[i].money;
    }

    int temp=0;
    cout<<"重要捐款人:"<<endl;
    for(int m=0;m<n_of_donation;m++)
    {
        if(list[m].money>10000)
        {
            cout<<list[m].name<<"     "<<list[m].money<<endl;
            temp++;
        }
    }
    if(temp==0)
        cout<<"None.\n";

    temp=0;
    cout<<"捐款人: "<<endl;
    for(int o=0;o<n_of_donation;o++)
    {
        if(list[o].money<=10000)
        {
            cout<<list[o].name<<"     "<<list[o].money<<endl;
            temp++;
        }
    }
    if(temp==0)
        cout<<"None!\n";

    delete []list;   //注意这行
    getchar();
    getchar();
    return 0;

} 
2016-04-05 19:00
快速回复:这段代码有问题吗,在编译的时候会出现崩溃的现象
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018259 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved