Free Essay

Pt1420 Assignment9

In:

Submitted By Quame
Words 484
Pages 2
Assignment 9 1. A function is a module that sends a value back to the part that it was called. A module a part of a program that does a specific task. 2. Set result = half (number)
Function Integer half(integer number) Declare integer num Input num number = num /2 return number
End function 3. Set results = cube(4) 4.
Module Module1

Sub Main() Dim testscore As Integer Dim total As Integer = 0 Dim Avg As Double Dim grade As String = "No Value"

For index = 1 To 5 Console.Write("Enter test score of " & index & ": ") testscore = Console.ReadLine() While testscore < 0 Or testscore > 100 Console.WriteLine("Enter a valid testscore.") Console.Write("Enter test score of " & index & ": ") testscore = Console.ReadLine() End While total = total + testscore grade = determineGrade(testscore, grade) displaygrades(testscore, grade) Next

Avg = calcAverage(total, Avg) displayAverage(Avg) Console.ReadLine() End Sub Function calcAverage(ByVal total As Integer, ByVal Avg As Double) Avg = total / 5 Return Avg End Function

Function determineGrade(ByVal testscore, ByVal grade) If testscore < 60 Then grade = "F" ElseIf testscore < 69 Then grade = "D" ElseIf testscore < 79 Then grade = "C" ElseIf testscore < 89 Then grade = "B" ElseIf testscore <= 100 Then grade = "A" End If

Return grade End Function Sub displaygrades(ByVal testscore As Integer, ByVal grade As String) Console.WriteLine(" " & testscore & " -- " & grade) End Sub Sub displayAverage(ByVal Avg As Double) Console.WriteLine("Average test score is : " & Avg) End Sub
End Module

1. If a program reads a bad data input, it would produce bad data to the user. 2. If an invalid data is put in, an error message is displayed to prompt the user to input a valid input.

1. Dim num as integer = 0
Console.Writeline(“Enter a positive number: “) num = console.Readline() while num < 0 console.writeline(“I said enter a positive number not a negative number.”) console.write(“Enter a positive number : “) num= console.Readline()
End While

2. Dim num as integer = 0
Console.Writeline(“Enter a number from 1 to 100: “) num = console.Readline() while num < 0 or num > 100 console.writeline(“I said enter a positive number not a negative number.”) console.write(“Enter a positive number : “) num= console.Readline()
End While

1.
Module Module1

Sub Main() Dim hourlyrate As Double Dim hoursworked As Double Dim grosspay As Double

Console.Write("Enter employee's hourly rate: ") hourlyrate = Console.ReadLine() While hourlyrate < 7.5 Or hourlyrate > 18.25 Console.WriteLine("Enter a valid pay.") Console.Write("Enter employee's hourly rate: ") hourlyrate = Console.ReadLine() End While

Console.Write("Enter number of hours worked: ") hoursworked = Console.ReadLine() While hoursworked < 0 Or hoursworked > 40 Console.WriteLine("Enter a valid pay.") Console.Write("Enter employee's hours worked: ") hoursworked = Console.ReadLine() End While

grosspay = hourlyrate * hoursworked

Console.WriteLine("Groos pay is: " & grosspay) Console.ReadLine()

End Sub

End Module

Similar Documents