# Visual basic: Need help finding the average of students

Page 1 of 1

## 11 Replies - 4537 Views - Last Post: 12 April 2013 - 08:06 AMRate Topic: 1 Votes //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=318265&amp;s=0ee47572b2b7837d98ff0d13729f9a90&md5check=' + ipb.vars['secure_hash'], cur_rating: 5, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 mandeepcheema11

Reputation: 0
• Posts: 9
• Joined: 11-April 13

# Visual basic: Need help finding the average of students

Posted 11 April 2013 - 02:43 PM

im a begginer in visual basic and my teacher wants to find out the marks of bunch of students and then make the program output the number of students entered and everage. also the output of how many students failed.

my program does number of students and total marks they gained but doesn't do average and how many failed.
please let me know how to convert my total into average and display how many students have failed

```Sub Main()
Dim p, total As Double
Dim Answer As String = "yes"
Dim numberofstudents As Integer
Dim average As Double
total = 0
numberofstudents = 0
p = 0
average = total / numberofstudents

Console.WriteLine(" enter a mark, yes or no??")
numberofstudents = numberofstudents + 1
total = total + p
Console.WriteLine(" would you like to know more?")
Loop
Console.WriteLine(" average is " & total & " for " & numberofstudents & " students ")
End sub

```

This post has been edited by AdamSpeight2008: 11 April 2013 - 02:45 PM

Is This A Good Question/Topic? 0

## Replies To: Visual basic: Need help finding the average of students

### #2 modi123_1

• Suitor #2

Reputation: 14045
• Posts: 56,207
• Joined: 12-June 08

## Re: Visual basic: Need help finding the average of students

Posted 11 April 2013 - 02:49 PM

Perhaps use the 'number of students' to size out an array or use 'list(of' collection to hold the information as it comes in and then you can process it for sums, average, failing, etc after it has been entered.

### #3 mandeepcheema11

Reputation: 0
• Posts: 9
• Joined: 11-April 13

## Re: Visual basic: Need help finding the average of students

Posted 11 April 2013 - 02:57 PM

modi123_1, on 11 April 2013 - 02:49 PM, said:

Perhaps use the 'number of students' to size out an array or use 'list(of' collection to hold the information as it comes in and then you can process it for sums, average, failing, etc after it has been entered.

sorry but im a complete noob on creating this. i need help on setting up the program, if you can show me an example that would be perfect.

[quote name='mandeepcheema11' date='11 April 2013 - 02:55 PM' timestamp='1365717347' post='1834770']

modi123_1, on 11 April 2013 - 02:49 PM, said:

Perhaps use the 'number of students' to size out an array or use 'list(of' collection to hold the information as it comes in and then you can process it for sums, average, failing, etc after it has been entered.

sorry but im a complete noob on creating this. i need help on setting up the program, if you can show me an example that would be perfect. my teacher has not gotten into lists and arrays yet so i have no idea.

[quote name='mandeepcheema11' date='11 April 2013 - 02:55 PM' timestamp='1365717347' post='1834770']

modi123_1, on 11 April 2013 - 02:49 PM, said:

Perhaps use the 'number of students' to size out an array or use 'list(of' collection to hold the information as it comes in and then you can process it for sums, average, failing, etc after it has been entered.

sorry but im a complete noob on creating this. i need help on setting up the program, if you can show me an example that would be perfect. my teacher has not gotten into lists and arrays yet so i have no idea.

### #4 modi123_1

• Suitor #2

Reputation: 14045
• Posts: 56,207
• Joined: 12-June 08

## Re: Visual basic: Need help finding the average of students

Posted 11 April 2013 - 02:58 PM

If I show you an example that is literally the solution. This type of homework assignment's goal is to show you the use of an array or collection. I suggest going back over your material.

### #5 mandeepcheema11

Reputation: 0
• Posts: 9
• Joined: 11-April 13

## Re: Visual basic: Need help finding the average of students

Posted 11 April 2013 - 03:06 PM

modi123_1, on 11 April 2013 - 02:58 PM, said:

If I show you an example that is literally the solution. This type of homework assignment's goal is to show you the use of an array or collection. I suggest going back over your material.

i understand but we were given no knowledge on this, and this is for practice not any test. Its for my self to learn and so far i haven't understood it.

### #6 andrewsw

• blow up my boots

Reputation: 6544
• Posts: 26,532
• Joined: 12-December 12

## Re: Visual basic: Need help finding the average of students

Posted 11 April 2013 - 03:22 PM

```average = total / numberofstudents
```

but it is in the wrong place. It should be calculated after you've worked out the total and the numberofstudents.

### #7 mandeepcheema11

Reputation: 0
• Posts: 9
• Joined: 11-April 13

## Re: Visual basic: Need help finding the average of students

Posted 11 April 2013 - 03:38 PM

andrewsw, on 11 April 2013 - 03:22 PM, said:

```average = total / numberofstudents
```

but it is in the wrong place. It should be calculated after you've worked out the total and the numberofstudents.

i tried putting it under loop , it still giving me the total amount with number of students but no average.

### #8 andrewsw

• blow up my boots

Reputation: 6544
• Posts: 26,532
• Joined: 12-December 12

## Re: Visual basic: Need help finding the average of students

Posted 11 April 2013 - 03:43 PM

mandeepcheema11, on 11 April 2013 - 10:38 PM, said:

i tried putting it under loop , it still giving me the total amount with number of students but no average.

This sounds to me like you've just moved this line somewhere without attempting to work out where it should be placed, and what other adjustments to your code might be necessary. Further study required!

This post has been edited by andrewsw: 11 April 2013 - 03:45 PM

• MrCupOfT

Reputation: 2298
• Posts: 9,535
• Joined: 29-May 08

## Re: Visual basic: Need help finding the average of students

Posted 11 April 2013 - 03:50 PM

How you use the debugger tools and stepped through the code.

It's not just about tools its also am analytic thought process.

Do the steps the program take, follow the route you think it should take?
Do the contents of the variables at each step, match what you expect?

If its not matching what is expect, don't change a single character.
Go reread the documentation of the functions and methods used.

### #10 mandeepcheema11

Reputation: 0
• Posts: 9
• Joined: 11-April 13

## Re: Visual basic: Need help finding the average of students

Posted 11 April 2013 - 08:11 PM

i am able to put the average on and number of students, but the only thing i am missing now is number of stuents that failed.
everything works fine but it displays a 0 beside students failed.
help with this last part please

```        Dim p, total As Double
Dim Answer As String = "yes"
Dim numberofstudents As Integer
Dim average As Double
Dim mark As Double
total = 0
numberofstudents = 0
p = 0
mark = 0

Console.WriteLine(" enter a mark, yes or no??")
numberofstudents = numberofstudents + 1
total = total + p
Console.WriteLine(" would you like to know more?")
Loop

average = total / numberofstudents

Console.WriteLine(" average is " & average & " for " & numberofstudents & " students ")
Console.WriteLine("Number of students failed = " & mark & "")
```

This post has been edited by AdamSpeight2008: 11 April 2013 - 08:22 PM
Reason for edit:: Please learn to use the CODE tags.

• MrCupOfT

Reputation: 2298
• Posts: 9,535
• Joined: 29-May 08

## Re: Visual basic: Need help finding the average of students

Posted 11 April 2013 - 08:29 PM

Just posting the same code and asking the same question, repeatedly make you look lazy and stupid. Are you?

Is record each score? or is it combining them some how?
What is a Failure? How do you recognize a failure?
what are you planning to do about it?

This post has been edited by AdamSpeight2008: 11 April 2013 - 08:31 PM

### #12 vks.gautam1

• D.I.C Regular

Reputation: 17
• Posts: 325
• Joined: 21-March 08

## Re: Visual basic: Need help finding the average of students

Posted 12 April 2013 - 08:06 AM

mandeepcheema11, on 11 April 2013 - 08:11 PM, said:

i am able to put the average on and number of students, but the only thing i am missing now is number of stuents that failed.
everything works fine but it displays a 0 beside students failed.
help with this last part please

```        Dim p, total As Double
Dim Answer As String = "yes"
Dim numberofstudents As Integer
Dim average As Double
Dim mark As Double
total = 0
numberofstudents = 0
p = 0
mark = 0

Console.WriteLine(" enter a mark, yes or no??")
numberofstudents = numberofstudents + 1
total = total + p
Console.WriteLine(" would you like to know more?")
Loop

average = total / numberofstudents

Console.WriteLine(" average is " & average & " for " & numberofstudents & " students ")
Console.WriteLine("Number of students failed = " & mark & "")
```

why don't you use if else condition.you havn't make any calculation on your mark variable. try it in between
```Do While Answer = "yes"
numberofstudents = numberofstudents + 1
' try here your mark variable
total = total + p
Console.WriteLine(" would you like to know more?")