4344번 - 평균은 넘겠지
위가 틀린 풀이
아래가 맞은 풀이입니다.
studentAverageScoreAboveStudentRatio = ((double)studentAverageScoreAboveStudentCount / (double)studentNumber * 100.0);
해당 문장을 for문 안에서 밖으로 뺐을 뿐인데... 출력되는 값은 변함 없는데 왜 틀린 건지 모르겠습니다.
제가 모르는 무엇인가가 있다면 도움 부탁드립니다.
만일 평균을 넘는 학생이 하나도 없다면,
studentAverageScoreAboveStudentRatio = ((double)studentAverageScoreAboveStudentCount / (double)studentNumber * 100.0);는 호출되지 못하고,
그럼 초기화 되지 않은 변수인 studentAverageScoreAboveStudentRatio의 쓰레기값이 출력될 수 있기 때문입니다.
감사합니다.
덕분에 해결할 수 있었습니다!
댓글을 작성하려면 로그인해야 합니다.
goisak100 2년 전
위가 틀린 풀이
아래가 맞은 풀이입니다.
studentAverageScoreAboveStudentRatio = ((double)studentAverageScoreAboveStudentCount / (double)studentNumber * 100.0);
해당 문장을 for문 안에서 밖으로 뺐을 뿐인데... 출력되는 값은 변함 없는데 왜 틀린 건지 모르겠습니다.
제가 모르는 무엇인가가 있다면 도움 부탁드립니다.