비주얼 베이직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
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 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
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
이런식으로 코드를 짜고 평균평점을 구하려고하니 어떻게 해줘야 될지 몰라서 질문드립니다.
A학점=4점
B =3
c=2
d=1
f=0
이런식으로 해서 평균평점을 구하는 프로그램을 만들려고하는데 저기서 더 어떻게 추가해줘야되는지 고수님들 부탁드립니다..
안녕하세요?
1. 일부 불필요 코드는 제거하고, 점수 계산 부분만 추가하면 되겠습니다.
2. 코드는 아래와 같습니다.
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 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 txtGrade.Text
Case "A"
intScore = 4
Case "B"
intScore = 3
Case "C"
intScore = 2
Case "D"
intScore = 1
Case "F"
intScore = 0
End Select
' TextBox 하나를 추가한후 txtScore로 Name을 줍니다.
txtScore.Text = intScore.ToString()
'-------------------------------------------------------
' 이하 아래의 나머지 코드는 제거합니다.
'''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
3. 함수 부분을 공부하셔서 함수화 하면 코드가 더욱 간결해지리라 봅니다.
질문에 답변이 되었기를 바랍니다.
감사합니다.
written by
JustineBaek
C과외/C#과외/VB과외 프로그래밍 과외.서울인천경기-방문강의.기타전국-화상강의.제대로 체계적으로 배우고싶은분들.15년경력 프리랜서.삼성/포스코/한진 등.
서울,인천,경기,분당,일산,과천,산본,부천,부평,평촌,안산,안양,광명,용인,시흥,성남,수원,평택,오산,화성,동탄,천안,아산,
c#프로그래밍1:1과외, 15년 이상 프로젝트 경력의 프리랜서 직접 강의,
c#프로그래밍 과외, c#프로그래밍교육, IT·컴퓨터·컴퓨터과외비·프로그래밍과외, c# 강좌, c# 프로그래밍,
데이터베이스, 데이터베이스 프로그래밍, db, DB, 과외비,컴퓨터1:1,컴퓨터개인지도,컴퓨터실무과외,컴퓨터과외,컴퓨터1:1과외,
서울,인천,경기,부천,안산,분당,일산,천안,과천,산본,안양,광명,평촌,수원,평택,오산,용인,부평,시흥,성남,화성,동탄
광주,부산,대구,대전,마산,창원,울산,전주,군산,원주,강릉,충청남도,충청북도,강원도,경상남도,경상북도,전라남도,전라북도,제주도
'좋은질문' 카테고리의 다른 글
VB 비주얼베이직 평점계산기 질문 (0) | 2014.10.07 |
---|---|
VB 비주얼베이직2010 평균평점 계산기 (0) | 2014.10.06 |
[C#] FOR 반복문 >> WHILE 반복문으로 바꾸는법좀 알려주세요 ㅠㅠ제발 (0) | 2014.10.04 |
VB 비주얼 베이직 실습문제 질문있습니다 (0) | 2014.10.03 |
VB 비주얼 베이직 자료에 대해 질문해봐여 (0) | 2014.10.02 |