| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 569 人关注过本帖
标题:c++初学者的问题
只看楼主 加入收藏
墨香555
Rank: 2
等 级:论坛游民
帖 子:115
专家分:31
注 册:2010-10-21
结帖率:96.15%
收藏
已结贴  问题点数:20 回复次数:3 
c++初学者的问题
#include<iostream>
struct golf
{
    double x;
    double y;
};
int main()
{
    using namespace std;
    const  int SIZE=10;
    int i=2,j;
    golf a[SIZE];
    double b[SIZE];
    cout<<"#1:";
    while((cin>>a[i].x)&&(cin>>a[i].y))
    {
        cout<<"#"<<i<<":";
        b[i]=(a[i].x+a[i].y)/2;
        i++;
        if(i>SIZE){i--;break;}
    }
    cout<<i<<endl;
    for(j=1;j<i;j++)                                《A》
    {
        cout<<"#"<<j<<" your score is :"<<a[j].x<<"   "<<a[j].y<<" and your average is "<<b[j]<<endl;
    }
    return 0;
}
这段代码有什么问题吗,怎么已运行起来就无限循环啊,我感觉是《A》出的i值问题,但不知道为什么啊
我输入:
#1:1 2
#2:3 6
#3:2 6
#4:3 6
#5:2 6
#6:2 6
#7:2 5
#8:2 5
#9:2 5(回车)
然后就出现下面的
#511 your score is :4.98461e-286   1016.49 and your average is 9.34582e-307
#512 your score is :1.35541e+244   0 and your average is 1.20162e-306
#513 your score is :0   3.18299e-312 and your average is 5.00668e-308
#514 your score is :0   0 and your average is 1.16821e-307
#515 your score is :0   0 and your average is 9.45701e-308
#516 your score is :2.54639e-312   8.48798e-314 and your average is 8.45595e-307

#517 your score is :1016.49   1.35541e+244 and your average is 9.791e-307
#518 your score is :4.20001e+020   4.98461e-286 and your average is 2.22523e-306

#519 your score is :1016.49   1.35541e+244 and your average is 5.00668e-308
#520 your score is :0   0 and your average is 1.057e-307
#521 your score is :3.18299e-312   0 and your average is 1.95812e-306
#522 your score is :0   0 and your average is 1.11262e-306
#523 your score is :0   2.54639e-312 and your average is 5.00668e-308
#524 your score is :8.48798e-314   2.12069e+062 and your average is 8.34424e-308

#525 your score is :3.81486e+074   583480 and your average is 5.00663e-308
#526 your score is :-1.62098e+288   2.12069e+062 and your average is 5.11798e-30
7
#527 your score is :3.81486e+074   0 and your average is 3.44898e-307
#528 your score is :0   2.71615e-312 and your average is 5.11798e-307
#529 your score is :0   0 and your average is 2.13618e-306
#530 your score is :0   0 and your average is 7.56577e-307
#531 your score is :2.54639e-312   8.48798e-314 and your average is 9.346e-307
#532 your score is :2.12069e+062   3.81486e+074 and your average is 6.2306e-307
#533 your score is :583480   -1.62098e+288 and your average is 6.89791e-307
#534 your score is :2.12069e+062   3.81486e+074 and your average is 1.60219e-306

#535 your score is :0   0 and your average is 9.79108e-307
#536 your score is :2.71615e-312   0 and your average is 1.1126e-306
#537 your score is :0   0 and your average is 2.04722e-306
#538 your score is :0   2.54639e-312 and your average is 9.34584e-307
#539 your score is :8.48798e-314   4.77486e+052 and your average is 1.6022e-306
#540 your score is :-1.52049e+147   8.77519e+049 and your average is 1.02361e-30
6
#541 your score is :6.43609e+104   4.77486e+052 and your average is 8.45607e-307

#542 your score is :-1.52049e+147   0 and your average is 6.89812e-307
#543 your score is :0   2.24932e-312 and your average is 1.16821e-307
#544 your score is :0   0 and your average is 9.45701e-308
#545 your score is :0   0 and your average is 8.45595e-307
#546 your score is :2.54639e-312   8.48798e-314 and your average is 9.791e-307
#547 your score is :4.77486e+052   -1.52049e+147 and your average is 1.00132e-30
7
#548 your score is :8.77519e+049   6.43609e+104 and your average is 1.05695e-307

#549 your score is :4.77486e+052   -1.52049e+147 and your average is 8.06633e-30
8
#550 your score is :0   0 and your average is 6.89801e-307
#551 your score is :2.24932e-312   0 and your average is 1.27946e-307
#552 your score is :0   0 and your average is 7.56592e-307
#553 your score is :0   2.54639e-312 and your average is 1.33511e-306
#554 your score is :8.48798e-314   8.2345e-223 and your average is 1.69119e-306
#555 your score is :-1.28503e-112   5.22237e+037 and your average is 1.33515e-30
7
#556 your score is :2.37395e+093   8.2345e-223 and your average is 1.11259e-306
#557 your score is :-1.28503e-112   0 and your average is 1.69121e-306
#558 your score is :0   1.78248e-312 and your average is 8.34452e-308
#559 your score is :0   0 and your average is 8.90104e-307
#560 your score is :0   0 and your average is 8.34452e-308
#561 your score is :2.54639e-312   8.48798e-314 and your average is 2.04723e-306

#562 your score is :8.2345e-223   -1.28503e-112 and your average is 1.11261e-306

#563 your score is :5.22237e+037   2.37395e+093 and your average is 4.00529e-307

#564 your score is :8.2345e-223   -1.28503e-112 and your average is 9.34587e-307

#565 your score is :0   0 and your average is 1.16821e-307
#566 your score is :1.78248e-312   0 and your average is 1.22387e-307
#567 your score is :0   0 and your average is 1.11258e-307
#568 your score is :0   2.54639e-312 and your average is 9.45743e-308
#569 your score is :8.48798e-314   8.2345e-223 and your average is 1.16824e-307
#570 your score is :-1.28503e-112   8.40258e+038 and your average is 1.00132e-30
7
#571 your score is :-7.294e-016   8.2345e-223 and your average is 2.31421e-306
#572 your score is :-1.28503e-112   0 and your average is 2.6702e-307
#573 your score is :0   1.31564e-312 and your average is 1.05699e-307
#574 your score is :0   0 and your average is 1.39076e-307
#575 your score is :0   0 and your average is 2.31408e-306
#576 your score is :2.54639e-312   8.48798e-314 and your average is 2.6702e-307
#577 your score is :8.2345e-223   -1.28503e-112 and your average is 6.36599e-314

#578 your score is :8.40258e+038   -7.294e-016 and your average is 4.24399e-314
#579 your score is :8.2345e-223   -1.28503e-112 and your average is 6.36599e-314

#580 your score is :0   0 and your average is 1.97824e-320
#581 your score is :1.31564e-312   0 and your average is 2.88591e-312
#582 your score is :0   0 and your average is 3.39519e-312
#583 your score is :0   2.54639e-312 and your average is 4.92303e-312
#584 your score is :2.122e-314   10565.4 and your average is 9.41991e-313
#585 your score is :-1.91216e-007   2.49562e+073 and your average is 2.122e-314
#586 your score is :3.20924e-296   10565.4 and your average is 1.6976e-313
#587 your score is :-1.91216e-007   0 and your average is 2.122e-314
#588 your score is :0   8.48798e-313 and your average is 3.69561e-321
#589 your score is :0   0 and your average is 1.00811e-094
#590 your score is :0   0 and your average is 4.66839e-313
#591 your score is :2.54639e-312   2.122e-314 and your average is 4.24399e-313
#592 your score is :10565.4   -1.91216e-007 and your average is 1.71037e+215
#593 your score is :2.49562e+073   3.20924e-296 and your average is 1.31564e-312

#594 your score is :10565.4   -1.91216e-007 and your average is 4.24399e-313
#595 your score is :0   0 and your average is 2.13688e+079
#596 your score is :8.48798e-313   0 and your average is 4.24399e-313
#597 your score is :0   0 and your average is 4.24399e-313
#598 your score is :0   1.20946e+175 and your average is 4.434e-241
#599 your score is :2.122e-314   2.122e-314 and your average is 1.2732e-312
#600 your score is :1.35808e-312   8.48798e-313 and your average is 4.24399e-313

#601 your score is :1.78021e-306   1.24611e-306 and your average is -2.78235e+15
7
#602 your score is :1.24611e-306   -4.5256e+063 and your average is 4.24399e-313

#603 your score is :-1.86046e-270   1.96311e-312 and your average is 4.24399e-31
3
#604 your score is :8.48798e-314   1.58101e-322 and your average is -5.8337e-163

#605 your score is :8.48798e-313   4.94066e-324 and your average is 1.2732e-312
#606 your score is :1.39069e-309   0 and your average is 4.24399e-313
#607 your score is :0   0 and your average is -1.51474e+112
#608 your score is :0   0 and your average is 4.24399e-313
#609 your score is :0   0 and your average is 4.24399e-313
#610 your score is :0   0 and your average is -3.13651e-208
#611 your score is :0   0 and your average is 1.2732e-312
#612 your score is :0   0 and your average is 4.24399e-313
#613 your score is :0   0 and your average is 8.90078e-307
#614 your score is :0   0 and your average is 1.86921e-306
#615 your score is :0   0 and your average is 1.24611e-306
#616 your score is :0   0 and your average is 4.24399e-313
#617 your score is :0   0 and your average is 9.88131e-324
#618 your score is :0   0 and your average is 0
#619 your score is :0   0 and your average is 5.11798e-307
#620 your score is :0   0 and your average is 3.44898e-307
#621 your score is :0   0 and your average is 1.69118e-306
#622 your score is :0   0 and your average is 9.3461e-307
#623 your score is :0   0 and your average is 6.23038e-307
#624 your score is :0   0 and your average is 3.56047e-307
#625 your score is :0   0 and your average is 8.34452e-308
#626 your score is :0   0 and your average is 2.29179e-312
#627 your score is :0   0 and your average is 2.122e-313
#628 your score is :0   0 and your average is 0
#629 your score is :0   0 and your average is 2.13621e-306
#630 your score is :0   0 and your average is 1.4242e-306
#631 your score is :0   0 and your average is 1.24611e-306
#632 your score is :0   0 and your average is 4.24399e-313
#633 your score is :0   0 and your average is 9.88131e-324
#634 your score is :0   0 and your average is 0
#635 your score is :0   0 and your average is 5.11798e-307
#636 your score is :0   0 and your average is 3.44898e-307
#637 your score is :0   0 and your average is 1.69118e-306
#638 your score is :0   0 and your average is 9.3461e-307
#639 your score is :0   0 and your average is 6.23038e-307
#640 your score is :0   0 and your average is 1.6022e-306
#641 your score is :0   0 and your average is 8.90061e-307
#642 your score is :0   0 and your average is 3.49699e-317
#643 your score is :0   0 and your average is 2.122e-313
#644 your score is :0   0 and your average is 0
#645 your score is :0   0 and your average is 1.78021e-306
#646 your score is :0   0 and your average is 1.24611e-306
#647 your score is :0   0 and your average is 1.24611e-306
#648 your score is :0   0 and your average is 4.24399e-313
#649 your score is :0   0 and your average is 9.88131e-324
#650 your score is :0   0 and your average is 0
#651 your score is :0   0 and your average is 5.11798e-307
#652 your score is :0   0 and your average is 3.44898e-307
#653 your score is :0   0 and your average is 1.69118e-306
#654 your score is :0   0 and your average is 9.3461e-307
#655 your score is :0   0 and your average is 6.23038e-307
#656 your score is :0   0 and your average is 8.90097e-307
#657 your score is :0   0 and your average is 8.90061e-307
#658 your score is :0   0 and your average is 3.49699e-317
#659 your score is :0   0 and your average is 2.122e-313
#660 your score is :0   0 and your average is 0
#661 your score is :0   0 and your average is 1.78021e-306
#662 your score is :0   0 and your average is 1.69119e-306
#663 your score is :0   0 and your average is 1.24611e-306
#664 your score is :0   0 and your average is 4.24399e-313
#665 your score is :0   0 and your average is 9.88131e-324
#666 your score is :0   0 and your average is 0
#667 your score is :0   0 and your average is 5.11798e-307
#668 your score is :0   0 and your average is 3.44898e-307
#669 your score is :0   0 and your average is 1.69118e-306
#670 your score is :0   0 and your average is 9.3461e-307
#671 your score is :0   0 and your average is 6.23038e-307
#672 your score is :0   0 and your average is 1.60219e-306
#673 your score is :0   0 and your average is 8.90061e-307
#674 your score is :0   0 and your average is 3.49699e-317
#675 your score is :0   0 and your average is 2.122e-313
#676 your score is :0   0 and your average is 0
#677 your score is :0   0 and your average is 6.36599e-314
#678 your score is :0   0 and your average is 4.24399e-314
#679 your score is :0   0 and your average is 4.24399e-314
#680 your score is :0   0 and your average is 8.48798e-314
#681 your score is :0   0 and your average is 9.33678e-313
#682 your score is :0   0 and your average is 1.95224e-312
#683 your score is :0   0 and your average is 1.44296e-312
#684 your score is :0   0 and your average is 2.97079e-312
#685 your score is :0   0 and your average is 1.20946e+175
#686 your score is :0   0 and your average is 2.122e-314
#687 your score is :0   0 and your average is 2.122e-314
#688 your score is :0   0 and your average is 6.96015e-312
#689 your score is :0   0 and your average is 8.48798e-313
#690 your score is :0   0 and your average is 1.78021e-306
#691 your score is :0   0 and your average is 1.24611e-306
#692 your score is :0   0 and your average is 1.24611e-306
#693 your score is :0   0 and your average is 1.29062e-306
#694 your score is :0   0 and your average is 8.3445e-308
#695 your score is :0   0 and your average is 2.29179e-312
#696 your score is :0   0 and your average is 1.6022e-306
#697 your score is :0   0 and your average is 8.90061e-307
#698 your score is :0   0 and your average is 8.9003e-307
#699 your score is :0   0 and your average is 1.78021e-306
#700 your score is :0   0 and your average is 1.24611e-306
#701 your score is :0   0 and your average is 2.13621e-306
#702 your score is :0   0 and your average is 1.4242e-306
#703 your score is :0   0 and your average is 1.24611e-306
#704 your score is :0   0 and your average is 1.29062e-306
#705 your score is :0   0 and your average is 8.3445e-308
#706 your score is :0   0 and your average is 2.29179e-312
#707 your score is :0   0 and your average is 1.6022e-306
#708 your score is :0   0 and your average is 8.90061e-307
#709 your score is :0   0 and your average is 8.9003e-307
#710 your score is :0   0 and your average is 1.78021e-306
#711 your score is :0   0 and your average is 1.24611e-306
#712 your score is :0   0 and your average is 2.13621e-306
#713 your score is :0   0 and your average is 1.4242e-306
#714 your score is :0   0 and your average is 1.24611e-306
#715 your score is :0   0 and your average is 1.29062e-306
#716 your score is :0   0 and your average is 8.3445e-308
#717 your score is :0   0 and your average is 2.29179e-312
#718 your score is :0   0 and your average is 1.6022e-306
#719 your score is :0   0 and your average is 8.90061e-307
#720 your score is :0   0 and your average is 8.9003e-307
#721 your score is :0   0 and your average is 1.78021e-306
#722 your score is :0   0 and your average is 1.24611e-306
#723 your score is :0   0 and your average is 2.13621e-306
#724 your score is :0   0 and your average is 1.4242e-306
#725 your score is :0   0 and your average is 1.24611e-306
#726 your score is :0   0 and your average is -7.17899e+218
#727 your score is :0   0 and your average is 1.41254e-262
#728 your score is :0   0 and your average is 3.51437e-311
#729 your score is :0   0 and your average is 6.36599e-314
#730 your score is :0   0 and your average is 8.23191e-223
#731 your score is :0   0 and your average is -3.48673e+173
#732 your score is :0   0 and your average is 2.54639e-312
#733 your score is :0   0 and your average is 3.93807e-165
#734 your score is :0   0 and your average is -2.04963
#735 your score is :0   0 and your average is 2.752e-311
#736 your score is :0   0 and your average is 6.36599e-314
#737 your score is :0   0 and your average is 1.34446e+046
#738 your score is :0   0 and your average is 1.75859e-293
#739 your score is :0   0 and your average is 2.54639e-312
#740 your score is :0   0 and your average is 6.35714e+179
#741 your score is :0   0 and your average is 1.06431e-299
#742 your score is :0   0 and your average is 4.27889e-311
#743 your score is :0   0 and your average is 6.36599e-314
#744 your score is :0   0 and your average is 10565.4
#745 your score is :0   0 and your average is -1.91216e-007
#746 your score is :0   0 and your average is 2.54639e-312
#747 your score is :0   0 and your average is 2.12499e-063
#748 your score is :0   0 and your average is 2.39903e-020
#749 your score is :0   0 and your average is 8.0991e-311
#750 your score is :0   0 and your average is 6.36599e-314
#751 your score is :0   0 and your average is 2.12069e+062
#752 your score is :0   0 and your average is 3.81486e+074
#753 your score is :0   0 and your average is 2.54639e-312
#754 your score is :0   0 and your average is 1.07092e-066
#755 your score is :0   0 and your average is 1.35886e-231
#756 your score is :0   0 and your average is 7.84429e-311
#757 your score is :0   0 and your average is 6.36599e-314
#758 your score is :0   0 and your average is 7.67531e+007
#759 your score is :0   0 and your average is -0.897377
#760 your score is :0   0 and your average is 2.54639e-312
#761 your score is :0   0 and your average is 4.64974e+022
#762 your score is :0   0 and your average is 3.02959e-010
#763 your score is :0   0 and your average is 5.29821e-311
#764 your score is :0   0 and your average is 6.36599e-314
#765 your score is :0   0 and your average is 5.22237e+037
#766 your score is :0   0 and your average is 2.37395e+093
#767 your score is :0   0 and your average is 2.54639e-312
#768 your score is :0   0 and your average is 2.04012e-026
#769 your score is :0   0 and your average is 1.61191e+286
#770 your score is :0   0 and your average is 7.07969e-311
#771 your score is :0   0 and your average is 6.36599e-314
#772 your score is :0   0 and your average is 583480
#773 your score is :0   0 and your average is -1.62098e+288
#774 your score is :0   0 and your average is 2.54639e-312
#775 your score is :0   0 and your average is 1.36408e-210
#776 your score is :0   0 and your average is 5.44436e-137
#777 your score is :0   0 and your average is 6.82618e-311
#778 your score is :0   0 and your average is 6.36599e-314
#779 your score is :0   0 and your average is 1.68676e+035
#780 your score is :0   0 and your average is 2.07043e+060
#781 your score is :0   0 and your average is 2.54639e-312
#782 your score is :0   0 and your average is -2.36971e-209
#783 your score is :0   0 and your average is 7.22236e+212
#784 your score is :0   0 and your average is 6.06046e-311
#785 your score is :0   0 and your average is 6.36599e-314
Press any key to continue
搜索更多相关主题的帖子: double golf include 
2011-09-06 16:25
czsbc
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
帖 子:469
专家分:1700
注 册:2008-12-13
收藏
得分:0 
程序代码:
 while((cin>>a[i].x)&&(cin>>a[i].y))
    {
        cout<<"#"<<i<<":";
        b[i]=(a[i].x+a[i].y)/2;
        i++;
        if(i>SIZE){i--;break;}
    }
上面的代码中i=10的时候没有跳出循环,要去执行cin>>a[i].x,发现没有,这样会出现访问越界呢
2011-09-06 17:09
墨香555
Rank: 2
等 级:论坛游民
帖 子:115
专家分:31
注 册:2010-10-21
收藏
得分:0 
回复 2楼 czsbc
越界?i的值最大不是SIZE=10吗,当i=11的时候不是已经break了吗
2011-09-06 17:50
czsbc
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
帖 子:469
专家分:1700
注 册:2008-12-13
收藏
得分:20 
a[i]中的i只能取到9的。
2011-09-06 18:00
快速回复:c++初学者的问题
数据加载中...
 
   



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

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