いちばん失敗した人決定戦

while文で5科目の平均点を求めるプログラムをどうやって作るのですか?

A 回答 (2件)

普通はキーボードを使ってコードを入力するのが主流ですね。


その後コンパイルできれば完成です^ ^
    • good
    • 0

#include <iostream>


#include <string>
#include <vector>

using namespace std;

class Test {
private: string subject;
private: int points;
public:
 Test(string s, int p) : subject(s), points(p) {}
 int GetPoints() {
  return this->points;
 }
};

int main(void) {
 vector<Test> scores{Test("国語", 90),
           Test("数学", 91),
           Test("英語", 97),
           Test("理科", 92),
           Test("社会", 80)};
 auto i = scores.size();
 int sum = 0;
 while (i > 0) {
  sum += scores[i-1].GetPoints();
  i--;
 }
 cout << sum/scores.size() << endl;
 return 0;
}
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!