[問題] c++出現的錯誤
開發平台(Platform):C++
問題(Question):我有除錯有過,但是計算時就出了問題,
不會問我該輸入幾分,請問我該修正哪個部份,謝謝
程式碼(Code):
using namespace std;
class student
{
public:
int average_score(){ return (eng + math + c)/3; }
void setID(int i){ id = i; }
void setName(char* str){ strcpy(name,str); }
void engScore(int score){ eng = score; }
void mathScore(int score){ math = score; }
void cppScore(int score){ c = score; }
private:
char name[10];
int id;
int eng;
int math;
int c;
};
int main(int argc, char *argv[])
{
char* str1;
int id;
int score;
student allan_name;
cout<<"請輸入學生姓名:";
cin>>str1;
allan_name.setName(str1);
cout<<"請輸入學生學號:";
cin>>id;
allan_name.setID(id);
cout<<"請輸入英文成績:";
cin>>score;
allan_name.engScore(score);
cout<<"請輸入數學成績:";
cin>>score;
allan_name.mathScore(score);
cout<<"請輸入C++成績:";
cin>>score;
allan_name.cppScore(score);
cout<<"平均分數為:" << allan_name.average_score();
system("PAUSE");
return EXIT_SUCCESS;
}
補充說明(Supplement):無
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.166.165.253
推
04/14 04:04, , 1F
04/14 04:04, 1F
→
04/14 04:38, , 2F
04/14 04:38, 2F
→
04/14 11:27, , 3F
04/14 11:27, 3F
※ 編輯: kevin888 來自: 118.166.170.234 (04/14 15:53)