精英盒子 -> 程序设计 -> 谁帮我看看这句C++代码有什么错 [打印本页]

abort 2012-06-10 11:45

谁帮我看看这句C++代码有什么错


cout<<"Enter the information about the students;"<<endl;
    cin>>student[0].strName;
    cin>>(stedent[0].chinese);              //这句是错的
    cin>>student[0].math;
    cin>>student[0].english;
    ......;

jybox 2012-06-10 12:09
单论这几句是没有错误...

abort 2012-06-10 12:21
#include <iostream>
#include <string>
using namespace std;
struct student_info
{
       string strName;
       int chinese;
       int math;
       int english;
};
student_info student[35];
int main()
{
    cout<<"Enter the information about the students;"<<endl;
    cin>>student[0].strName;
    cin>>stedent[0].chinese;
    cin>>student[0].math;
    cin>>student[0].english;
    ......;
    cin>>student[34].strName;
    cin>>stedent[34].chinese;
    cin>>student[34].math;
    cin>>student[34].english;
    cout<<"Show the information about the students :"<<endl;
    cout<<"Name:"<<student[0].strName;
    cout>>"Chinese performance:"<<student[0].chinese;
    cout>>"Math performance:"<<student[0].math;
    cout>>"English performance:"<<student[0].english;
    ......;
    cout<<"Name:"<<student[34].strName;<<endl;
    cout>>"Chinese performance:"<<student[34].chinese;<<endl;
    cout>>"Math performance:"<<student[34].math;<<endl;
    cout>>"English performance:"<<student[34].english;<<endl;
    cout<<"Average of Chinese:"<<
         (student[0].chinese+
         student[1].chinese+
         student[2].chinese+
         student[3].chinese+
         student[4].chinese+
         student[5].chinese+
         student[6].chinese+
         student[7].chinese+
         student[8].chinese+
         student[9].chinese+
         student[10].chinese+
         student[11].chinese+
         student[12].chinese+
         student[13].chinese+
         student[14].chinese+
         student[15].chinese+
         student[16].chinese+
         student[17].chinese+
         student[18].chinese+
         student[19].chinese+
         student[20].chinese+
         student[21].chinese+
         student[22].chinese+
         student[23].chinese+
         student[24].chinese+
         student[25].chinese+
         student[26].chinese+
         student[27].chinese+
         student[28].chinese+
         student[29].chinese+
         student[30].chinese+
         student[31].chinese+
         student[32].chinese+
         student[33].chinese+
         student[34].chinese/35<<endl;
cout<<"Average of Math : "<<
         (student[0].math+
         student[1].math+
         student[2].math+
         student[3].math+
         student[4].math+
         student[5].math+
         student[6].math+
         student[7].math+
         student[8].math+
         student[9].math+
         student[10].math+
         student[11].math+
         student[12].math+
         student[13].math+
         student[14].math+
         student[15].math+
         student[16].math+
         student[17].math+
         student[18].math+
         student[19].math+
         student[20].math+
         student[21].math+
         student[22].math+
         student[23].math+
         student[24].math+
         student[25].math+
         student[26].math+
         student[27].math+        
         student[28].math+
         student[29].math+
         student[30].math+        
         student[31].math+
         student[32].math+
         student[33].math+
         student[34].math+/35<<endl;
cout<<Average of English:"<<
         student[0].english+
         student[1].math+
         student[2].math+
         student[3].math+
         student[4].math+
         student[5].math+
         student[6].math+
         student[7].math+
         student[8].math+
         student[9].math+
         student[10].math+
         student[11].math+
         student[12].math+
         student[13].math+
         student[14].math+
         student[15].math+
         student[16].math+
         student[17].math+
         student[18].math+
         student[19].math+
         student[20].math+
         student[21].math+
         student[22].math+
         student[23].math+
         student[24].math+
         student[25].math+
         student[26].math+
         student[27].math+        
         student[28].math+
         student[29].math+
         student[30].math+        
         student[31].math+
         student[32].math+
         student[33].math+
         student[34].math+/35<<endl;
cin.get();
return 0;
)

whtsky 2012-06-10 12:47
真有毅力...

whtsky 2012-06-10 12:53
咳...看到错了
我的建议是直接重构

lookatmeyou 2012-06-10 13:06
whtsky:咳...看到错了
我的建议是直接重构 (2012-06-10 12:53) 

麻烦提醒一下  jybox  快给我发货。

whtsky 2012-06-10 14:42
lookatmeyou:麻烦提醒一下  jybox  快给我发货。 (2012-06-10 13:06) 

那个...我也联系不到他呀-_-#...mail他不回么?

jybox 2012-06-10 17:40
whtsky:
那个...我也联系不到他呀-_-#...mail他不回么?


是啊..你后来发邮件我40秒就回了....

话说淘宝其他功能都可以设置邮件提醒,为毛唯独发货不可以...

jybox 2012-06-10 17:42
回楼主:

0. 需要重构+1,请学习循环语句用法
1. 除法优先级高于加法,要算平均数请给加法加括号
2.最后一行,应该是右花括号

以上为目测,没跑编译器

另建议楼主看下《提问的智慧》

abort 2012-06-11 18:57
第一次写的C++




Powered by phpwind v8.7 Code ©2003-2011 phpwind
Time 0.047155 second(s),query:5 Gzip enabled