VB 비주얼베이직2010 평균평점 계산기
비주얼 베이직2010으로 평균평점 계산기를 만드는중입니다(초심자)
Public Class frmGrade
Private Sub btnTask_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTask.Click
Dim count, sum As Integer
Dim avg As Double
Dim intscore As Integer
If chkIntro.Checked = True Then
count = count + 1
sum = sum + CInt(txtIntro.Text)
End If
If chkOS.Checked = True Then
count = count + 1
sum = sum + CInt(txtOS.Text)
End If
If chkCS.Checked = True Then
count = count + 1
sum = sum + CInt(txtCS.Text)
End If
If chkSW.Checked = True Then
count = count + 1
sum = sum + CInt(txtSW.Text)
End If
If chkDB.Checked = True Then
count = count + 1
sum = sum + CInt(txtDB.Text)
End If
txtSum.Text = sum
avg = sum / count
txtAvg.Text = avg
If txtIntro.Text >= 90 Then
IntroG.Text = "A"
ElseIf txtIntro.Text >= 80 Then
IntroG.Text = "B"
ElseIf txtIntro.Text >= 70 Then
IntroG.Text = "C"
ElseIf txtIntro.Text >= 60 Then
IntroG.Text = "D"
Else
IntroG.Text = "F"
End If
If txtOS.Text >= 90 Then
OSG.Text = "A"
ElseIf txtOS.Text >= 80 Then
OSG.Text = "B"
ElseIf txtOS.Text >= 70 Then
OSG.Text = "C"
ElseIf txtOS.Text >= 60 Then
OSG.Text = "D"
Else
OSG.Text = "F"
End If
If txtCS.Text >= 90 Then
CSG.Text = "A"
ElseIf txtCS.Text >= 80 Then
CSG.Text = "B"
ElseIf txtCS.Text >= 70 Then
CSG.Text = "C"
ElseIf txtCS.Text >= 60 Then
CSG.Text = "D"
Else
CSG.Text = "F"
End If
If txtSW.Text >= 90 Then
SWG.Text = "A"
ElseIf txtSW.Text >= 80 Then
SWG.Text = "B"
ElseIf txtSW.Text >= 70 Then
SWG.Text = "C"
ElseIf txtSW.Text >= 60 Then
SWG.Text = "D"
Else
SWG.Text = "F"
End If
If txtDB.Text >= 90 Then
DBG.Text = "A"
ElseIf txtDB.Text >= 80 Then
DBG.Text = "B"
ElseIf txtDB.Text >= 70 Then
DBG.Text = "C"
ElseIf txtDB.Text >= 60 Then
DBG.Text = "D"
Else
DBG.Text = "F"
End If
If avg >= 90 Then
txtGrade.Text = "A"
ElseIf avg >= 80 Then
txtGrade.Text = "B"
ElseIf avg >= 70 Then
txtGrade.Text = "C"
ElseIf avg >= 60 Then
txtGrade.Text = "D"
Else
txtGrade.Text = "F"
End If
Select Case IntroG.Text
Case "A"
intscore = 4
Case "B"
intscore = 3
Case "C"
intscore = 2
Case "D"
intscore = 1
Case "F"
intscore = 0
End Select
Select Case OSG.Text
Case "A"
intscore = 4
Case "B"
intscore = 3
Case "C"
intscore = 2
Case "D"
intscore = 1
Case "F"
intscore = 0
End Select
Select Case CSG.Text
Case "A"
intscore = 4
Case "B"
intscore = 3
Case "C"
intscore = 2
Case "D"
intscore = 1
Case "F"
intscore = 0
End Select
Select Case SWG.Text
Case "A"
intscore = 4
Case "B"
intscore = 3
Case "C"
intscore = 2
Case "D"
intscore = 1
Case "F"
intscore = 0
End Select
Select Case DBG.Text
Case "A"
intscore = 4
Case "B"
intscore = 3
Case "C"
intscore = 2
Case "D"
intscore = 1
Case "F"
intscore = 0
End Select
이까지 하고 이제 평균 평점 구하는 식
'txtavgr.Text = intscore.ToString((IntroG.Text * intro1.Text) + (OSG.Text * OS1.Text) + (CSG.Text * CS1.Text) + (SWG.Text * Sw1.Text) + (DBG.Text * Db1.Text)) / (intro1.Text + OS1.Text + CS1.Text + Sw1.Text + Db1.Text)
을 넣어주면 프로그램은 실행되나 각 과목의 점수와 이수시간을 넣고 계산을 하면 오류가 나버립니다. 무엇이 잘못 되었는지 잘 모르겠습니다. 도와주십시오..
(IntroG~DbG 는 각각의 과목의 등급입니다. IF 구문을 쓴 이유는 각 과목의 등급을 알려주기 위해서입니다.)
각 등급에 대한 점수는
A=4
b=3
c=2
d=1
f=0
으로 주었습니다.
안녕하세요? 1. 평균평점 부분 수정이 필요합니다. 2. 작성하신 코드에 몇 가지 논리적인 오류가 있습니다. -. score 변수를 각각 선언 필요합니다. (학점이 intScore에 뭉쳐버립니다.) -. (점수 * 학점) 부분에서 점수를 잘못 곱했습니다. -. 한분이 지적하신 것처럼 숫자 계산시 형변환이 필요합니다. -. 수정한 코드는 아래와 같습니다. 전체코드는 아니며, 보시면 어느 부분인지 판단하실 수 있을겁니다. 3. 수정된 코드(각각의 학점을 변수에 기억) Dim introScore As Integer Dim osScore As Integer Dim csScore As Integer Dim swScore As Integer Dim dbScore As Integer ' 이제 평점평균을 구합니다. Dim intScore As Integer ' sum(각점수 * 학점) / sum(학점) : +_(밑줄)은 행을 바꾸어도 같은 명령줄로 인식. intScore = ((CInt(txtIntro.Text) * introScore) + _ ' 계산완료된 점수를 표시합니다. txtavgr.Text = intScore.ToString() 4.덧붙여 두어가지 조언을 드린다면, -. 첫째는 함수(메서드) 부분을 꼭 공부하시어, 코드를 모듈화 하기 입니다. 일반적으로 버튼 클릭과 같은 이벤트 구간에서는 화면의 동작제어 코드만 기술하고, 실제 업무적인 기능은 함수로 작성하여, 적절한 호출만 해줍니다. -. 둘째는 타이핑에 앞서 꼭 전체적인 흐름을 설계하고 먼저 노트하는 습관들이기 입니다. 습관이란 참 무서운 놈이지요. 해버릇하면 쉬운데, 안해버릇하면 죽어도 못합니다. -. 이제 막 시작하는 단계이므로 이 모든 과정은 지극히 자연스러운 현상입니다만, 그저 방향 삼아 참고 하였으면 싶어 말씀 드려 보았습니다. 질문 주신 부분에 답변이 되었기를 바랍니다. 감사합니다. written by JustineBaek C과외/C#과외/VB과외 프로그래밍 과외.서울인천경기-방문강의.기타전국-화상강의.제대로 체계적으로 배우고싶은분들.15년경력 프리랜서.삼성/포스코/한진 등. 서울,인천,경기,분당,일산,과천,산본,부천,부평,평촌,안산,안양,광명,용인,시흥,성남,수원,평택,오산,화성,동탄,천안,아산, c#프로그래밍1:1과외, 15년 이상 프로젝트 경력의 프리랜서 직접 강의, c#프로그래밍 과외, c#프로그래밍교육, IT·컴퓨터·컴퓨터과외비·프로그래밍과외, c# 강좌, c# 프로그래밍, 데이터베이스, 데이터베이스 프로그래밍, db, DB, 과외비,컴퓨터1:1,컴퓨터개인지도,컴퓨터실무과외,컴퓨터과외,컴퓨터1:1과외, 서울,인천,경기,부천,안산,분당,일산,천안,과천,산본,안양,광명,평촌,수원,평택,오산,용인,부평,시흥,성남,화성,동탄 광주,부산,대구,대전,마산,창원,울산,전주,군산,원주,강릉,충청남도,충청북도,강원도,경상남도,경상북도,전라남도,전라북도,제주도IntroG.Text -> txtIntro.Text 가 되어야함.
Select Case introG.Text
Case "A"
introScore = 4
Case "B"
introScore = 3
Case "C"
introScore = 2
Case "D"
introScore = 1
Case "F"
introScore = 0
End Select
Select Case osG.Text
Case "A"
osScore = 4
Case "B"
osScore = 3
Case "C"
osScore = 2
Case "D"
osScore = 1
Case "F"
osScore = 0
End Select
Select Case csG.Text
Case "A"
csScore = 4
Case "B"
csScore = 3
Case "C"
csScore = 2
Case "D"
csScore = 1
Case "F"
csScore = 0
End Select
Select Case swG.Text
Case "A"
swScore = 4
Case "B"
swScore = 3
Case "C"
swScore = 2
Case "D"
swScore = 1
Case "F"
swScore = 0
End Select
Select Case dbG.Text
Case "A"
dbScore = 4
Case "B"
dbScore = 3
Case "C"
dbScore = 2
Case "D"
dbScore = 1
Case "F"
dbScore = 0
End Select
(CInt(txtOS.Text) * osScore) + _
(CInt(txtCS.Text) * csScore) + _
(CInt(txtSW.Text) * swScore) + _
(CInt(txtDB.Text) * dbScore)) / _
(introScore + osScore + csScore + swScore + dbScore)