게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
C++ 질문이요..
게시물ID : computer_139622짧은주소 복사하기
작성자 : 익명이요
추천 : 0
조회수 : 293회
댓글수 : 8개
등록시간 : 2014/01/02 11:37:16
혼자 독학하고 있는데..

다른 건 다 잘되는 데, 평균값이 자꾸 int값으로 나오네요.

뭐가 문젠지 정말 모르겠어요ㅜㅜ

// 성적표 프로그램 Ver 1.1 (+구조체사용)
#include <iostream>
#include <iomanip>
using namespace std;
struct Score
{
unsigned int kor;
unsigned int eng;
unsigned int math;
double average;
};
int main()
{
cout.precision(2); // 소수점 이하 두자리까지 표시.
unsigned int studentNum = 1;

cout << "**********성적표 프로그램**********" << endl << endl;

Score p1, p2, p3;
p1.kor = 0; p1.eng = 0; p1.math = 0; p1.average = 0;
p2.kor = 0; p2.eng = 0; p2.math = 0; p2.average = 0;
p3.kor = 0; p3.eng = 0; p3.math = 0; p3.average = 0;

while (1)
{

cout << "----------      Menu     ----------" << endl << endl;
cout << "1. 학생 성적 추가" << endl;
cout << "2. 전체 성적 보기" << endl;
cout << "q. 프로그램 종료" << endl << endl;
cout << "원하는 작업의 번호을 입력하세요 : ";
char job;
cin >> job; cout << endl;
if (job == '1')
{
if (studentNum == 1) // 학생의 숫자가 1명일 때
{
cout << "학생 성적 추가가 선택되었습니다." << endl << endl;
cout << "국어, 영어, 수학 점수를 입력하세요 : ";
cin >> p1.kor >> p1.eng >> p1.math; cout << endl;
(double)p1.average = (p1.kor + p1.eng + p1.math) / 3;
cout << "학생 성적이 올바르게 입력되었습니다." << endl;
studentNum++;
}
else if (studentNum == 2) // When number of student is 2.
{
cout << "학생 성적 보기가 선택되었습니다." << endl << endl;
cout << "국어, 영어, 수학 점수를 입력하세요 : ";
cin >> p2.kor >> p2.eng >> p2.math; cout << endl;
(double)p2.average = (p2.kor + p2.eng + p2.math) / 3;
cout << "학생 성적이 올바르게 입력되었습니다." << endl;
studentNum++;

}
else if (studentNum == 3) // When number of student is 3.
{
cout << "학생 성적 추가가 선택되었습니다." << endl << endl;
cout << "국어, 영어, 수학 점수를 입력하세요 : ";
cin >> p3.kor >> p3.eng >> p3.math; cout << endl;
(double)p3.average = (p3.kor + p3.eng + p3.math) / 3;
cout << "학생 성적이 올바르게 입력되었습니다." << endl;
studentNum++;

}
else
{
cout << endl;
cout << "3명까지 성적입력이 가능합니다." << endl << endl;
}
}
else if (job == '2')
{
cout << "전체 성적 보기가 선택되었습니다." << endl << endl;
cout << "학번  국어   영어   수학   평균" << endl;
cout << setw(3) << "1" << setw(7) << p1.kor << setw(7) << p1.eng << setw(7) << p1.math << setw(7) << p1.average << endl;
cout << setw(3) << "2" << setw(7) << p2.kor << setw(7) << p2.eng << setw(7) << p2.math << setw(7) << p2.average << endl;
cout << setw(3) << "3" << setw(7) << p3.kor << setw(7) << p3.eng << setw(7) << p3.math << setw(7) << p3.average << endl;
cout << endl << "전체 평균 : " << double(p1.average + p2.average + p3.average) / 3; cout << endl << endl;
}
else if (job == 'q')
{
cout << "프로그램을 종료합니다." << endl << endl;
exit(1);
}
else
{
cout << "다시 입력해주세요" << endl << endl;
}
}
return 0;
}
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호