# "Operator '<' is not defined for type 'Integer()&#

Page 1 of 1

## 3 Replies - 1303 Views - Last Post: 27 November 2012 - 08:24 AMRate Topic: 1 Votes //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=301766&amp;s=c32f0c1f515ba282b7bddbfa998d37a3&md5check=' + ipb.vars['secure_hash'], cur_rating: 4, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 jakeelsley96

Reputation: 0
• Posts: 2
• Joined: 27-November 12

# "Operator '<' is not defined for type 'Integer()&#

Posted 27 November 2012 - 07:53 AM

I'm trying to do a basic console application that displays the student's name, mark and then says if their grade is above, equal or below to the average.

I am having an error displaying wether the grade is above, equal or below.

When using a Sub I get this error: "Expression does not produce a value", and when using a Function, I get this error: "Operator '<' is not defined for type 'Integer()' and type 'Integer'".

Any help would be greatly appreciated.

Here is my code:

```Module Module1

Sub Main()
Dim Student() As String = {"Fred", "Jack", "Chris", "Ali", "Harry", "Bill", "Zak", "Phil"}
Dim Mark() As Integer = {"67", "25", "92", "49", "38", "72", "99", "54"}
Dim Average As Integer = (Mark(0) + Mark(1) + Mark(2) + Mark(3) + Mark(4) + Mark(5) + Mark(6) + Mark(7)) / 8

AverageCalc(Average, Mark)
For x = 0 To 7
Console.WriteLine(Student(x) & " " & Mark(x) & " - " & AverageCalc(Average, Mark))
Next
'Dim Average As Integer = (Mark(0) + Mark(1) + Mark(2) + Mark(3) + Mark(4) + Mark(5) + Mark(6) + Mark(7)) / 8
Console.WriteLine(Average)
End Sub
Sub AverageCalc(Average, Mark)
Do
If Mark < Average Then
Console.WriteLine("Lower than average")
If Mark = Average Then
Console.WriteLine("Same as average")
If Mark > Average Then
Console.WriteLine("Higher than average")
End If
End If
End If
Loop
End Sub
End Module

```

Is This A Good Question/Topic? 0

## Replies To: "Operator '<' is not defined for type 'Integer()&#

### #2 ipushmycar

• D.I.C Regular

Reputation: 86
• Posts: 390
• Joined: 29-August 10

## Re: "Operator '<' is not defined for type 'Integer()&#

Posted 27 November 2012 - 08:04 AM

You are trying to compare an array of integers with an integer. You need to access an element of the array and compare it. Ex:

```If Mark(1) = 1 Then
MsgBox("The element with index 1 is value 1.")
End If

```

### #3 jakeelsley96

Reputation: 0
• Posts: 2
• Joined: 27-November 12

## Re: "Operator '<' is not defined for type 'Integer()&#

Posted 27 November 2012 - 08:16 AM

@ipushmycar

Ahh okay that makes sense. Thank you.

### #4 lucky3

• Friend lucky3 As IHelpable

Reputation: 233
• Posts: 770
• Joined: 19-October 11

## Re: "Operator '<' is not defined for type 'Integer()&#

Posted 27 November 2012 - 08:24 AM

Couple of notes:

In line 6, where you calculate your Average, use appropriate value type, because Integer is not going to show you a decimal part of the average. In this particular case, you'll get the right result, but if one of the students would have grade better or worse by only one point, calculated average wouldn't be precise.

It would be wise to exit infinite loop at some point also.

Your Marks array is of Integer type, but you're feeding it with strings. There's no need to have quotation marks ("") around each integer.

Your AverageCalc method should be function, if you plan to use the return value for displaying textual evaluation of students' results.

Its parameters should be specified by type, and when you're calling this method, you'd probably want to tell the method, which mark (from what index in Marks array) should be compared to average.

Nested If statements aren't going to give you the expected result, either. If first condition isn't met, then code inside it will not be accessed, so if mark wouldn't be below average, you'd never be able to evaluate if it's average, or above it.

This post has been edited by lucky3: 27 November 2012 - 08:25 AM