Question

Using visual studio C# Create a method for generating 3 random scores. You decide to go...

Using visual studio C#

Create a method for generating 3 random scores.
You decide to go for array/list/dictionary. Set the return type and other stuff consistently.
Use a loops inside the method to generate random scores and assign scores to the data structure.
Return the structure as a whole.
Clarification: One run of the method is to generate data for one student. You need to run the method 4 times, one for each student.

Keep other things the same. That is:


2-dimension structure


Calculate average score


Display all scores and average score


Call students as Jim, Corey, Rick, and Bryan

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi,

Program:

// C# program to demonstrate the
// boolean data type
using System;
using System.Collections;
using System.Collections.Generic;

namespace ValueTypeTest {
  
   class GeeksforGeeks {
      
   // Main function
   static void Main()
   {
      
       Console.WriteLine("----------------");

       Console.WriteLine("Jim marks:");
      
       int sum =0;
       ArrayList jim = genscores();
       foreach(int i in jim)
{
Console.WriteLine(i);
sum +=i;
}
       Console.WriteLine("Average:" + sum/3);
      
       Console.WriteLine("----------------");

       Console.WriteLine("Corey marks:");
      
       sum =0;
       ArrayList c = genscores();
       foreach(int i in c)
{
Console.WriteLine(i);
sum +=i;
}
       Console.WriteLine("Average:" + sum/3);
      
       Console.WriteLine("----------------");
       Console.WriteLine("Rick marks:");
      
       sum =0;
       ArrayList r = genscores();
       foreach(int i in r)
{
Console.WriteLine(i);
sum +=i;
}
       Console.WriteLine("Average:" + sum/3);
      
       Console.WriteLine("----------------");

       Console.WriteLine("Bryan marks:");
      
       sum =0;
       ArrayList b = genscores();
       foreach(int i in b)
{
Console.WriteLine(i);
sum +=i;
}
       Console.WriteLine("Average:" + sum/3);
  
   }
  
   static ArrayList genscores(){
  
   Random rand = new Random();

ArrayList myList = new ArrayList(10);
  
for(int i=0;i<3;i++){
int index = rand.Next(40, 100);
myList.Add(index);
}
return myList;
}
}
}

output:

----------------
Jim marks:
93
41
40
Average:58
----------------
Corey marks:
98
52
88
Average:79
----------------
Rick marks:
98
52
88
Average:79
----------------
Bryan marks:
98
52
88
Average:79

Screenshot:

Jim marks: 75 88 Average: 71 Corey marks: Average: 71 Rick marks: 75 Average: 71 Bryan marks: 75 Average: 71

Add a comment
Know the answer?
Add Answer to:
Using visual studio C# Create a method for generating 3 random scores. You decide to go...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT