1

对于这个问题,我需要让用户输入一个数字,然后接收教师的姓名、当前工资和新工资。我试过这样的东西

Dim Names(10)as String
Dim Yos(10) as Integer
Dim Sal(10) as Integer
Dim Nsal(10) as Integer
Dim Rate(10) as Integer
Teachers = 2
Teacher_Num = 0
Dim Number as Integer
Dim Answer as String

PRINT " Congrats! 10 of you have been chosen to receive a raise in your salary :D. Please follow instructions below :)."

For Count = 1 To Teachers

    Teacher_Num = Teacher_Num + 1
    Print "Your number is:",Teacher_Num
    Input " Nice to meet you! What's your name? :D ",Names(10)
    Input " How many years have you serve here :O?",Yos(10)
    Input "What is your current Salary?",Sal(10)

IF Sal(10) > 1 then

    Rate(10)= (Yos(10) * 2) +100
    Nsal(10) = Rate(10) * (Sal(10))/100
    Print " Your name is: ",Names(10)
    Print " Your Previous Salary was: ",Sal(10)
    Print " Your New Salary is: ",Nsal(10)
    Print " Thank you for your time :D, Please allow the next user to begin. (*Dear new user, Please press enter to begin*)"
End If
If Count = Teachers Then

    Input "Would you like to see a specific name and current salary of a teacher or yourself?",Answer   
If Answer = "Yes" or Answer = "yes" Then

    Input "Please input the Teacher's Number",Number
    Print "Here's your information: ",Names(Number),Sal(Number),Nsal(Number) `Else`
    If Answer = "No" OR Answer = "no" Then
      End If
End If
End If
Sleep
Next
End

但它不起作用(下面的链接显示错误)请有人帮忙!这是给 Sba 的……我的老师不久前想让我的班级输入成绩,但没有人知道如何做到这一点,所以知道有人提交了……我已经尝试这样做好几天了,但我们从来没有被教过太多关于数组:(

4

2 回答 2

0

第一个问题是Names(10),Rate(10)等应该是Names(Count), Rate(Count), 等等。

Count1 到 10,您希望在阵列中使用该插槽。每次您的 FOR...NEXT 块循环时,Names(Count)都会解析为Names(1), Names(2), Names(3)... Names(10)

第二期

Yos, Sal, Nsal, 和Rate应该被定义为Double而不是Integer。整数不会计算小数,因此在计算新工资时会丢失精度(如果我输入 30000 作为我一年的工资,它会显示 -202 而不是 30600)。如果您打算四舍五入到最接近的美元,那么使用双精度并CINT()四舍五入到最接近的整数:

Dim Yos(10) as Double
Dim Sal(10) as Double
Dim Nsal(10) as Double
Dim Rate(10) as Double
...
Rate(Count) = (Yos(Count) * 2) + 100
Nsal(Count) = CINT(Rate(Count) * (Sal(Count)) / 100)
于 2018-04-10T14:24:18.170 回答
0

首先,您必须初始化所有变量和数组。对于你想做的事情,单独的 FOR 循环是不合适的 复制这个源代码并编译它以了解如何工作

如果您不明白某些想法,请随时提问

'  Declare it is not indispensable but useful if you want to know how many and which SUB and FUNCTION are inside the program when the code is long.
Declare SUB Salary()  

Sub Salary()
    ' We make a multi dimensional array is more usefull 
    Dim as String Identity(10,5) 

    ' We initialize the variables by giving a value that we will use as an index
    Dim as Integer Teachernum = 1, NameTeacher = 2, YearOfServe = 3, CurrentSalary = 4, FutureSalary = 5

    ' We initialize a string variable to use as a prompt
    Dim As String PromptWord
    Dim As integer InsValue = 0 ' Initialize a var to use inside FOR Loop
    Dim As Integer TheExit = 0 ' Initialize a TheExit Var to use for the loop 
    Dim As Integer InsData = 1 ' You need for control the inser data
    Dim As String TeacherFound = "" ' You Need this var for print message status during search
    PRINT " Congrats! 10 of you have been chosen to receive a raise in your salary :D. Please follow instructions below :)."

    Do Until (TheExit = 1) 'make a loop while the variable TheExit is not equal to 1




        If InsData = 1 Then 'This start the data insert  if = 1

        For InsValue = 1 To 10 Step 1

         Identity(InsValue, Teachernum) = str(InsValue) ' Put in the array the number of teacher where the Index is same of loop step
         Print "Your number is:" & Identity(InsValue, Teachernum) 'We use the & symbol to join strings without spaces
         Line Input " Nice to meet you! What's your name? :D "; Identity(InsValue, NameTeacher) 'Put the name of teacher 
         Line Input " How many years have you serve here :O ?"; Identity(InsValue, YearOfServe) 'punt the year o service
         Line Input " What is your current Salary?"; Identity(InsValue, CurrentSalary) 'put current salary


            IF Val(Identity(InsValue, CurrentSalary)) > 1 then  'VAL converts a string into an integer value that can be calculated 

            ' With STR and VAL can calculate the value inside String array
            ' STR Convert a Integer to String
            ' VAL Conver a string to Integer

            ' I use this method to not initialize too many different types of variables
            Identity(InsValue, FutureSalary) = Str( ((Val(Identity(InsValue, YearOfServe)) * 2) +100) * Val(Identity(InsValue, CurrentSalary)) / 100)

            ' FutureSalary = ( (YearOfService * 2 ) +100 ) * CurrentSalary / 100 (If is this you want calculate
            ' Rate(10)= (Yos(10) * 2) +100
            ' Nsal(10) = Rate(10) * (Sal(10))/100

                Print " Your name is: " & Identity(InsValue,NameTeacher)
                Print " Your Previous Salary was: " & Identity(InsValue, CurrentSalary)
                Print " Your New Salary is: " & Identity(InsValue,FutureSalary)
                Print " Thank you for your time :D, Please allow the next user to begin. (*Dear new user, Please press enter to begin*)"

            End If

         Line Input " Press Enter for continue... ";  PromptWord 'Ask for enter for jump to the next





        Next InsValue
        InsData = 0 ' When loop this dont stat the Insert data
    End if
    'Finish Loop now the check  ask if you want check the data inserted 
    Line Input "Would you like to see a specific name and current salary of a teacher or yourself ? Yes / No "; PromptWord
    TeacherFound = "" 'Reset the var

    If UCASE(PromptWord) = "YES"  Then  ' UCASE UCASE It transforms the string into capital letters so if you write with upper and lower case letters it does not differ
        Line Input "Please input the Teacher's Number or Name"; PromptWord
        For InsValue = 1 To 10 Step 1
            If ( Val(PromptWord) = Val(Identity(InsValue, Teachernum))) Or ( UCASE(PromptWord) = UCASE(Identity(InsValue,NameTeacher)) )Then 
                Print "Teacher Found num:" & Identity(InsValue, Teachernum)
                Print "Teacher Name:" &  Identity(InsValue,NameTeacher)
                Print "Previous Salary was: " & Identity(InsValue, CurrentSalary)
                Print "New Salary is: " & Identity(InsValue,FutureSalary)
                TeacherFound = "Found"
            Else
                TeacherFound = TeacherFound & "" 'Add a empty value each round
            End If

        Next InsValue 
        If TeacherFound = "" Then Print "No Teacher Found !" 
    Else
        Print "The Program is Done Press Enter for exit"
        Line Input PromptWord
        TheExit = 1 ' Make end to the loop Do until
    End If

    Loop

End Sub

' Call the Sub Salary like a command

Salary()

于 2020-04-05T20:53:43.947 回答