11 Replies - 1772 Views - Last Post: 12 April 2013 - 08:06 AM Rate Topic: ***** 1 Votes

#1 mandeepcheema11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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??")
 Answer = Console.ReadLine()
 Do While Answer = "yes"
 numberofstudents = numberofstudents + 1
 Console.WriteLine(" what is your mark?")
 p = Console.ReadLine
 total = total + p
 Console.WriteLine(" would you like to know more?")
 Answer = Console.ReadLine()
 Loop
 Console.WriteLine(" average is " & total & " for " & numberofstudents & " students ")
 Console.ReadLine()
 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  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9573
  • View blog
  • Posts: 36,253
  • 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.
Was This Post Helpful? 0
  • +
  • -

#3 mandeepcheema11  Icon User is offline

  • New D.I.C Head

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

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

Posted 11 April 2013 - 02:57 PM

View Postmodi123_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']

View Postmodi123_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']

View Postmodi123_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.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9573
  • View blog
  • Posts: 36,253
  • 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.
Was This Post Helpful? 0
  • +
  • -

#5 mandeepcheema11  Icon User is offline

  • New D.I.C Head

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

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

Posted 11 April 2013 - 03:06 PM

View Postmodi123_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.
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3812
  • View blog
  • Posts: 13,527
  • Joined: 12-December 12

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

Posted 11 April 2013 - 03:22 PM

Your code already includes this line

average = total / numberofstudents

but it is in the wrong place. It should be calculated after you've worked out the total and the numberofstudents.
Was This Post Helpful? 0
  • +
  • -

#7 mandeepcheema11  Icon User is offline

  • New D.I.C Head

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

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

Posted 11 April 2013 - 03:38 PM

View Postandrewsw, on 11 April 2013 - 03:22 PM, said:

Your code already includes this line

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.
Was This Post Helpful? 0
  • +
  • -

#8 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3812
  • View blog
  • Posts: 13,527
  • Joined: 12-December 12

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

Posted 11 April 2013 - 03:43 PM

View Postmandeepcheema11, 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

Was This Post Helpful? 0
  • +
  • -

#9 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • 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.
Was This Post Helpful? 0
  • +
  • -

#10 mandeepcheema11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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??")
        Answer = Console.ReadLine()
        Do While Answer = "yes"
            numberofstudents = numberofstudents + 1
            Console.WriteLine(" what is your mark?")
            p = Console.ReadLine
            total = total + p
            Console.WriteLine(" would you like to know more?")
            Answer = Console.ReadLine()
        Loop

        average = total / numberofstudents

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

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

Was This Post Helpful? 0
  • +
  • -

#11 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • 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?

What is your "actually" doing? Think about at an higher level..
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

Was This Post Helpful? 0
  • +
  • -

#12 vks.gautam1  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 317
  • Joined: 21-March 08

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

Posted 12 April 2013 - 08:06 AM

View Postmandeepcheema11, 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??")
        Answer = Console.ReadLine()
        Do While Answer = "yes"
            numberofstudents = numberofstudents + 1
            Console.WriteLine(" what is your mark?")
            p = Console.ReadLine
            total = total + p
            Console.WriteLine(" would you like to know more?")
            Answer = Console.ReadLine()
        Loop

        average = total / numberofstudents

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

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
            Console.WriteLine(" what is your mark?")
            p = Console.ReadLine
' try here your mark variable
            total = total + p
            Console.WriteLine(" would you like to know more?")
            Answer = Console.ReadLine()
        Loop



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1