좋은질문

VB 비주얼베이직 평점계산기 질문

JustineBaek 2014. 10. 7. 00:30

 

 

 

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 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

        Dim introscore As Integer

        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

        Dim osscore As Integer

        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

        Dim csscore As Integer

        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

        Dim swscore As Integer

        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

        Dim dbscore As Integer

        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

 

        평균평점 구하는 식>>txtavgr.Text = ((intro1.Text * introscore) + (OS1.Text * osscore) + (CS1.Text * csscore) + (Sw1.Text * swscore) + (Db1.Text * dbscore)) / (introscore + osscore + csscore + swscore + dbscore)

 

여기서

 

평균평점을 구하려는 식을 넣어줫음에도 불구하고

이수학점의 평균만 나옵니다. 뭐가 잘못됬나요

 

 

 

 

질문자 인사

궁금한 점이 시원하게 해결되었어요! 정말정말정말정말 감사드립니다!!!!! 이제 재대로 작동합니다 ㅠㅠ.. 제가진작에 저런식으로 질문을 했어야 됬는데 번거롭게 하여 죄송합니다.. 즐거운하루되십시오!

 

 

 

안녕하세요?

 

1. 진작 화면을 봤으면 좋았을 듯 싶네요..^^

 

' 추가해야 할 코드 

Dim reqestIntro As Integer = CInt(intro1.Text)     ' 이수학점 intro
Dim reqestOS As Integer = CInt(OS1.Text)         ' 이수학점 os 
Dim reqestCS As Integer = CInt(CS1.Text)          ' 이수학점 cs

Dim reqestSW As Integer = CInt(Sw1.Text)         ' 이수학점 sw
Dim reqestDB As Integer = CInt(Db1.Text)          ' 이수학점 db

 

' 추가에 따라 수정해야 할 코드

Dim intScore As Integer
intScore = ((introScore * reqestIntro) + _
                (osScore * reqestOS) + _
                (csScore * reqestCS) + _
                (swScore * reqestSW) + _
                (dbScore * reqestDB)) / _
               (reqestIntro + reqestOS + reqestCS + reqestSW + reqestDB)

 

txtavgr.Text = intScore.ToString()

 

2. sum(평가학점 * 이수학점) / sum(이수학점)

   분모는 이수학점의 합계로 나누는게 맞겠네요.

 

 

답변에 도움이 되시길 바랍니다.

감사합니다.

 

 

 

 

written by

  

JustineBaek

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

C과외/C#과외/VB과외 프로그래밍 과외.서울인천경기-방문강의.기타전국-화상강의.제대로 체계적으로 배우고싶은분들.15년경력 프리랜서.삼성/포스코/한진 등.

서울,인천,경기,분당,일산,과천,산본,부천,부평,평촌,안산,안양,광명,용인,시흥,성남,수원,평택,오산,화성,동탄,천안,아산,

c#프로그래밍1:1과외, 15년 이상 프로젝트 경력의 프리랜서 직접 강의,

c#프로그래밍 과외, c#프로그래밍교육, IT·컴퓨터·컴퓨터과외비·프로그래밍과외, c# 강좌, c# 프로그래밍,

데이터베이스, 데이터베이스 프로그래밍, db, DB, 과외비,컴퓨터1:1,컴퓨터개인지도,컴퓨터실무과외,컴퓨터과외,컴퓨터1:1과외,

서울,인천,경기,부천,안산,분당,일산,천안,과천,산본,안양,광명,평촌,수원,평택,오산,용인,부평,시흥,성남,화성,동탄

광주,부산,대구,대전,마산,창원,울산,전주,군산,원주,강릉,충청남도,충청북도,강원도,경상남도,경상북도,전라남도,전라북도,제주도