Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 16.28 KB | None | 0 0
  1.    Dim score_Number_Guessing_Game As Integer
  2.     Sub file_writing_and_reading()
  3.         Dim path As String
  4.         Dim line, line1, line2, line3, line4 As String
  5.  
  6.         path = "H:\yr 10\Year 10 computer sci\files\test.txt"
  7.         FileOpen(1, path, OpenMode.Output)
  8.         Console.WriteLine("enter the first line")
  9.         line = Console.ReadLine
  10.         Console.WriteLine("please enter the second line")
  11.         line1 = Console.ReadLine
  12.         Console.WriteLine("please enter the third line")
  13.         line2 = Console.ReadLine
  14.         Console.WriteLine("Please enter the fourth line")
  15.         line3 = Console.ReadLine
  16.         Console.WriteLine("please enter the last line")
  17.         line4 = Console.ReadLine
  18.         PrintLine(1, line)
  19.         PrintLine(1, line1)
  20.         PrintLine(1, line2)
  21.         PrintLine(1, line3)
  22.         PrintLine(1, line4)
  23.         FileClose(1)
  24.  
  25.         path = "H:\yr 10\Year 10 computer sci\files\test.txt"
  26.         FileOpen(1, path, OpenMode.Input)
  27.  
  28.         Do While Not EOF(1)
  29.             line = LineInput(1)
  30.             Console.WriteLine(line)
  31.             line1 = LineInput(1)
  32.             Console.WriteLine(line1)
  33.             line2 = LineInput(1)
  34.             Console.WriteLine(line2)
  35.             line3 = LineInput(1)
  36.             Console.WriteLine(line3)
  37.             line4 = LineInput(1)
  38.             Console.WriteLine(line4)
  39.             Console.ReadLine()
  40.         Loop
  41.  
  42.     End Sub
  43.  
  44.     Sub OverFlow_error()
  45.         Dim crash As Integer
  46.         Dim overflow As Integer
  47.         crash = 0
  48.         Console.WriteLine("Press enter to cause an over flow error")
  49.         Console.ReadLine()
  50.         crash = 1
  51.         While crash = 1
  52.             overflow = overflow + 10000
  53.             Console.WriteLine(overflow)
  54.             If overflow = 2147470000 Then
  55.                 crash = 0
  56.                 Console.WriteLine("press enter again to crash")
  57.                 Console.ReadLine()
  58.                 overflow = overflow + 20000
  59.                 Console.Clear()
  60.                 Main()
  61.                 Console.WriteLine(overflow)
  62.                 Console.ReadLine()
  63.                 overflow = 0
  64.             End If
  65.         End While
  66.     End Sub
  67.  
  68.     Sub currency_converter()
  69.         Dim choice As String ' varibles
  70.         Dim con As String
  71.         Dim gbp As Decimal
  72.  
  73.  
  74.  
  75.         Console.WriteLine("service charge: 5% if under £500 and 3% if over £500") ' this tells them that there is a service charge
  76.         Console.WriteLine("Please enter the amount you would like to convert (gbp): ") ' this asks them to enter the amount of money they would like to convert
  77.         gbp = Console.ReadLine()
  78.         If Decimal.TryParse(gbp, gbp) Then
  79.             Console.WriteLine("valid. number = " & gbp)
  80.  
  81.             If gbp <= 499 Then     ' This part calculates the service charge
  82.                 gbp = gbp * 0.95 ' 5% if its under £500
  83.             End If
  84.             If gbp >= 500 Then ' 3% if its over £500
  85.                 gbp = gbp * 0.97
  86.             End If
  87.  
  88.             If gbp < 0 Or gbp > 999999 Then 'this puts a limit on the amount they can convert to 999999
  89.                 Console.WriteLine("please enter a valid number between 0 and 999999") ' this tells that the number is too high or low
  90.                 Console.WriteLine("please press enter to continue")
  91.                 Console.ReadLine() ' the next 3 lines loops the program
  92.                 Console.Clear()
  93.                 Main()
  94.             End If
  95.  
  96.             Console.WriteLine()
  97.             Console.WriteLine("Please enter the currency you would like to convert into: ")
  98.             Console.WriteLine()
  99.             Console.WriteLine("******************************")
  100.             Console.WriteLine()
  101.             Console.WriteLine("1: United states Dollar (USD)")
  102.             Console.WriteLine("2: Euro (EUR)")
  103.             Console.WriteLine("3: Australian Dollar (AUD) ")
  104.             Console.WriteLine("4: Canadian Dollar (CAD) ")
  105.             Console.WriteLine("5: Swiss Franc (CHF) ")
  106.             Console.WriteLine("6: Hong Kong Dollar (HKD) ") ' this lists all of the currencys they can convert into
  107.             Console.WriteLine("7: Japanese Yen (JPY) ")
  108.             Console.WriteLine("8: Mexican Peseo (MXN) ")
  109.             Console.WriteLine("9: Indian Rupee (INR) ")
  110.             Console.WriteLine("10: New Zealand Dollar (NZD) ")
  111.             Console.WriteLine()
  112.             Console.WriteLine("******************************")
  113.             Console.WriteLine()
  114.             con = Console.ReadLine()
  115.  
  116.             If (con <= 0) Or (con >= 11) Then ' this makes sure its between 1 - 10
  117.                 Console.WriteLine("please enter a number between 1 and 10")
  118.                 Console.WriteLine("please press enter to continue")
  119.                 Console.ReadLine() ' loops program if its not between 1 - 10
  120.                 Console.Clear()
  121.                 Main()
  122.             End If
  123.  
  124.             While con = 1
  125.                 Console.WriteLine("you will get " & gbp * 1.61 & " usd For " & gbp & " gbp (after service charge) ") ' converts gbp to usd
  126.                 con = 0
  127.                 Console.WriteLine("Do you want convert another currency? [yes/no]") 'asks if you want to convert another currency
  128.                 choice = Console.ReadLine()
  129.                 If choice = "yes" Then ' if choice is yes then it loops the program
  130.                     Console.Clear()
  131.                     Main()
  132.                 Else
  133.                     End
  134.                 End If
  135.             End While
  136.  
  137.             While con = 2
  138.                 Console.WriteLine("you will get " & gbp * 1.22 & " eur for " & gbp & " gbp  (after service charge) ") ' converts euros
  139.                 con = 0
  140.                 Console.WriteLine("Do you want convert another currency? [yes/no]")
  141.                 choice = Console.ReadLine()
  142.                 If choice = "yes" Then
  143.                     Console.Clear()
  144.                     Main()
  145.                 Else
  146.                     End
  147.                 End If
  148.             End While
  149.  
  150.             While con = 3
  151.                 Console.WriteLine("you will get " & gbp * 1.55 & "aud for " & gbp & " gbp  (after service charge) ") ' converts aud
  152.                 con = 0
  153.                 Console.WriteLine("Do you want convert another currency? [yes/no]")
  154.                 choice = Console.ReadLine()
  155.                 If choice = "yes" Then
  156.                     Console.Clear()
  157.                     Main()
  158.                 Else
  159.                     End
  160.                 End If
  161.             End While
  162.  
  163.             While con = 4
  164.                 Console.WriteLine("you will get " & gbp * 1.59 & " cad for " & gbp & " gbp  (after service charge) ") ' converts cad
  165.                 con = 0
  166.                 Console.WriteLine("Do you want convert another currency? [yes/no]")
  167.                 choice = Console.ReadLine()
  168.                 If choice = "yes" Then
  169.                     Console.Clear()
  170.                     Main()
  171.                 Else
  172.                     End
  173.                 End If
  174.             End While
  175.  
  176.             While con = 5
  177.                 Console.WriteLine("you will get " & gbp * 1.46 & " chf for " & gbp & " gbp  (after service charge) ") ' converts chf
  178.                 con = 0
  179.                 Console.WriteLine("Do you want convert another currency? [yes/no]")
  180.                 choice = Console.ReadLine()
  181.                 If choice = "yes" Then
  182.                     Console.Clear()
  183.                     Main()
  184.                 Else
  185.                     End
  186.                 End If
  187.             End While
  188.  
  189.             While con = 6
  190.                 Console.WriteLine("you will get " & gbp * 1.25 & " hdk for " & gbp & " gbp  (after service charge) ") ' converts hdk
  191.                 con = 0
  192.                 Console.WriteLine("Do you want convert another currency? [yes/no]")
  193.                 choice = Console.ReadLine()
  194.                 If choice = "yes" Then
  195.                     Console.Clear()
  196.                     Main()
  197.                 Else
  198.                     End
  199.                 End If
  200.             End While
  201.  
  202.             While con = 7
  203.                 Console.WriteLine("you will get " & gbp * 1.31 & " jpy for " & gbp & " gbp  (after service charge) ") ' converts jpy
  204.                 con = 0
  205.                 Console.WriteLine("Do you want convert another currency? [yes/no]")
  206.                 choice = Console.ReadLine()
  207.                 If choice = "yes" Then
  208.                     Console.Clear()
  209.                     Main()
  210.                 Else
  211.                     End
  212.                 End If
  213.             End While
  214.  
  215.             While con = 8
  216.                 Console.WriteLine("you can get " & gbp * 2.12 & " mxn for " & gbp & " gbp  (after service charge) ") ' converts mxn
  217.                 con = 0
  218.                 Console.WriteLine("Do you want convert another currency? [yes/no]")
  219.                 choice = Console.ReadLine()
  220.                 If choice = "yes" Then
  221.                     Console.Clear()
  222.                     Main()
  223.                 Else
  224.                     End
  225.                 End If
  226.             End While
  227.             While con = 9
  228.                 Console.WriteLine("you can get " & gbp * 8.39 & " inr for " & gbp & " gbp  (after service charge) ") ' converts inr
  229.                 con = 0
  230.                 Console.WriteLine("Do you want convert another currency? [yes/no]")
  231.                 choice = Console.ReadLine()
  232.                 If choice = "yes" Then
  233.                     Console.Clear()
  234.                     Main()
  235.                 Else
  236.                     End
  237.                 End If
  238.             End While
  239.  
  240.             While con = 10
  241.                 Console.WriteLine("you can get " & gbp * 1.98 & " nzd for " & gbp & " gbp  (after service charge) ") ' converts nzd
  242.                 con = 0
  243.                 Console.WriteLine("Do you want convert another currency? [yes/no]")
  244.                 choice = Console.ReadLine()
  245.                 If choice = "yes" Then
  246.                     Console.Clear()
  247.                     Main()
  248.                 Else
  249.                     End
  250.                 End If
  251.             End While
  252.         End If
  253.     End Sub
  254.     Sub caluclator()
  255.  
  256.         Dim number_1 As Decimal
  257.         Dim number_2 As Decimal
  258.         Dim opr As String
  259.         Dim sum As Decimal
  260.         Dim choice As String
  261.  
  262.         Console.WriteLine("please enter your first number: ")
  263.         number_1 = Console.ReadLine()
  264.         Console.WriteLine()
  265.         Console.WriteLine("please enter your second number: ")
  266.         number_2 = Console.ReadLine()
  267.         Console.WriteLine()
  268.         Console.WriteLine("Please pick an operator from the list below : ")
  269.         Console.WriteLine()
  270.         Console.WriteLine("***************")
  271.         Console.WriteLine()
  272.         Console.WriteLine("1: + ")
  273.         Console.WriteLine("2: - ")
  274.         Console.WriteLine("3: x ")
  275.         Console.WriteLine("4: / ")
  276.         Console.WriteLine()
  277.         Console.WriteLine("***************")
  278.         opr = Console.ReadLine
  279.  
  280.         While opr = 1
  281.             sum = number_1 + number_2
  282.             Console.WriteLine("The 2 numbers added equals: " & sum & "")
  283.             opr = 0
  284.             Console.WriteLine()
  285.             Console.WriteLine("would you like to use the calculator again? [yes/no]")
  286.             choice = Console.ReadLine()
  287.         End While
  288.         If choice = "yes" Then
  289.             Console.Clear()
  290.             Main()
  291.  
  292.         End If
  293.  
  294.         While opr = 2
  295.             sum = number_1 - number_2
  296.             Console.WriteLine("The 2 numbers subtracted equals: " & sum & "")
  297.             opr = 0
  298.             Console.WriteLine()
  299.             Console.WriteLine("would you like to use the calculator again? [yes/no]")
  300.             choice = Console.ReadLine()
  301.         End While
  302.         If choice = "yes" Then
  303.             Console.Clear()
  304.             Main()
  305.         Else : End
  306.         End If
  307.  
  308.         While opr = 3
  309.             sum = number_1 * number_2
  310.             Console.WriteLine("The 2 numbers timed equals: " & sum & "")
  311.             opr = 0
  312.             Console.WriteLine()
  313.             Console.WriteLine("would you like to use the calculator again? [yes/no]")
  314.             choice = Console.ReadLine()
  315.         End While
  316.         If choice = "yes" Then
  317.             Console.Clear()
  318.             Main()
  319.         Else : End
  320.         End If
  321.  
  322.         While opr = 4
  323.             sum = number_1 - number_2
  324.             Console.WriteLine("The 2 numbers subtracted equals: " & sum & "")
  325.             opr = 0
  326.             Console.WriteLine()
  327.             Console.WriteLine("would you like to use the calculator again? [yes/no]")
  328.             choice = Console.ReadLine()
  329.         End While
  330.         If choice = "yes" Then
  331.             Console.Clear()
  332.             Main()
  333.         Else : End
  334.         End If
  335.  
  336.         While opr = 2
  337.             sum = number_1 / number_2
  338.             Console.WriteLine("The 2 numbers divided  equals: " & sum & "")
  339.             opr = 0
  340.             Console.WriteLine()
  341.             Console.WriteLine("would you like to use the calculator again? [yes/no]")
  342.             choice = Console.ReadLine()
  343.         End While
  344.         If choice = "yes" Then
  345.             Console.Clear()
  346.             Main()
  347.         Else : End
  348.         End If
  349.     End Sub
  350.     Sub guessing_game()
  351.  
  352.         Dim confirm As String
  353.         Dim guess As Integer
  354.         Dim mysterynumber As Integer
  355.         Dim choice As String
  356.  
  357.         Randomize()
  358.         mysterynumber = CInt(Math.Ceiling(Rnd() * 100))
  359.         If mysterynumber < 1 Then
  360.             Console.WriteLine("Error Number is smaller than 1!")
  361.             Console.ReadLine()
  362.         End If
  363.         If mysterynumber > 100 Then
  364.             Console.WriteLine("Error Number is bigger than 100!")
  365.             Console.ReadLine()
  366.         End If
  367.         guess = 0
  368.         While guess = 0
  369.             Console.WriteLine("score :" & score_Number_Guessing_Game & " ")
  370.             Console.WriteLine("please enter a guess between 1 and 100.")
  371.             guess = Console.ReadLine
  372.             If guess > mysterynumber Then
  373.                 guess = 0
  374.                 Console.WriteLine("your guess is too high")
  375.             ElseIf guess < mysterynumber Then
  376.                 guess = 0
  377.                 Console.WriteLine("Your guess is too low")
  378.             ElseIf guess = mysterynumber Then
  379.                 Console.WriteLine("well done you've guessed correctly!")
  380.                 Console.WriteLine("Score + 1")
  381.                 score_Number_Guessing_Game = score_Number_Guessing_Game + 1
  382.                 Console.WriteLine("would you like to play again? [Yes/No] ")
  383.                 choice = Console.ReadLine()
  384.                 If choice = "yes" Then
  385.                     guessing_game()
  386.                     Console.Clear()
  387.                 Else
  388.                     Console.WriteLine("are you sure you will lose your current score of " & score_Number_Guessing_Game & " [Yes/No] ")
  389.                     confirm = Console.ReadLine
  390.                     If confirm = "No" Then
  391.                         Console.Clear()
  392.                         guessing_game()
  393.                         If confirm = "Yes" Then
  394.                             Console.Clear()
  395.                             score_Number_Guessing_Game = 0
  396.                             Main()
  397.                         End If
  398.                     End If
  399.                 End If
  400.             End If
  401.         End While
  402.     End Sub
  403.     Sub Main()
  404.         Dim selection As Integer
  405.         Console.WriteLine("****************************")
  406.         Console.WriteLine()
  407.         Console.WriteLine("1: OverFlow error")
  408.         Console.WriteLine("2: currecny converter")
  409.         Console.WriteLine("3: caluclator")
  410.         Console.WriteLine("4: Guessing game")
  411.         Console.WriteLine("5: File writing and reading")
  412.         Console.WriteLine()
  413.         Console.WriteLine("****************************")
  414.         selection = Console.ReadLine()
  415.         If selection = 1 Then
  416.             Console.Clear()
  417.             OverFlow_error()
  418.         ElseIf selection = 2 Then
  419.             Console.Clear()
  420.             currency_converter()
  421.         ElseIf selection = 3 Then
  422.             Console.Clear()
  423.             caluclator()
  424.         ElseIf selection = 4 Then
  425.             Console.Clear()
  426.             guessing_game()
  427.         ElseIf selection = 5 Then
  428.             Console.Clear()
  429.             file_writing_and_reading()
  430.         End If
  431.  
  432.         Console.ReadLine()
  433.     End Sub
  434.  
  435.  
  436. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement