1

For this problem I need to have the user input a number and in return receive the Name, current salary and new salary of the teacher. I've tried something like this

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

But it doesn't work (The link below shows the error) Please someone help! This is for an Sba...My teacher wanted my class to input grades a while ago but no one knows how to do this so know one submitted... I've been trying to do this for days but we were never taught much about arrays :(

Marco van de Voort
  • 25,628
  • 5
  • 56
  • 89
Alysia56
  • 11
  • 2
  • Hi, in the spirit of being helpful, though I don't program in freebasic so won't post as answer, I have made some notes using VBA which gives you something to work from. They are close enough I trust you can gain something from it. If only to understand how arrays fit with your question.https://pastebin.com/ACgZebUd This character " ' " is used to signify a comment e.g. 'lcase means is a comment not code – QHarr Mar 18 '18 at 16:09
  • @Marco van de Voort thank you so much for your input! I'll try it asap – Alysia56 Mar 19 '18 at 19:17
  • ermmm... me? Lol – QHarr Mar 19 '18 at 19:19
  • I think so?...I'm so confused erm you're the one that commented on my question right? – Alysia56 Mar 19 '18 at 19:22
  • Lol. I posted the link with the comments. I tried to do a free basic version but couldn’t find a working online IDE to execute it. – QHarr Mar 19 '18 at 19:24
  • I only removed an erroneous pascal tag. – Marco van de Voort Mar 19 '18 at 19:26
  • 1
    @QHarr and Marco van de Voort I meant both of you then? I thought it was one account with two names so erm that's embarrassing But thanks so much! – Alysia56 Mar 19 '18 at 19:33
  • Maybe the first step is, to explain us why you use a fix element (10) in your loop? Shouldn´t that be the 'Count' instead of '10' ? – nabuchodonossor Mar 21 '18 at 10:34
  • @nabuchodonossor Yes it should have! QHarrr showed it to me in the link but for some reason the part where it asks to input the teacher's number to see a specific teacher doesn't work...I think the program ends up trying to multiply the number the user inserted with the variables that should show or something...because the only thing that displays is "14-×÷%%%" something like that – Alysia56 Mar 21 '18 at 11:31
  • I cant see any link – nabuchodonossor Mar 21 '18 at 12:42
  • @nabuchodonossor [1]: https://i.stack.imgur.com/RNOXQ.png – Alysia56 Mar 21 '18 at 12:46
  • As long you are not writing your data to the correct index, you will have no value in the than used index. Your error: you stored the value of Alysia in index 10, then the value of tina also in 10. Then you access index 1 - and there is nothing. Correct your program to use the Count Variable as index in your data entry loop. Then try again. – nabuchodonossor Mar 21 '18 at 14:19

2 Answers2

0

The first problem is that Names(10), Rate(10), etc. should be Names(Count), Rate(Count), etc.

As Count goes from 1 to 10, you want to be using that slot in the arrays. Each time your FOR...NEXT block loops, Names(Count) will resolve to Names(1), Names(2), Names(3) ... Names(10).

Second Issue

Yos, Sal, Nsal, and Rate should be defined as Double instead of Integer. Integers won't calculate decimals and so you'll lose precision when calculating the new salary (If I enter 30000 as my salary for one year, it shows -202 instead of 30600). If you intend to round to the nearest dollar, then use doubles for precision and CINT() to round to the nearest integer:

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)
Joe
  • 1,330
  • 13
  • 15
0

First of all you have to initialize all the variables and arrays. for what you want to do the FOR loop alone is not suitable Copy this source code and compile it for learn how work

If you dont understand somethink feel free to ask

'  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()

ExagonX
  • 141
  • 10