473,387 Members | 1,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Random class and arrays

Hello
I am having dificulty with this homework question ( I know its
homework but I have been trying for a while with this)
"generate 50 random numbers between 0 and 6 and count the number of
occurences of each value. IT should employ the DAyOfWeek enumeration,
where 0 represents Sunday....."

public class DayOfWeek {
enum Days {Sat, Sun, Mon, Tue, Wed, Thu, Fri};

int[] DayOfWeek = new int[7];
Random r = new Random();
for(int i = 0; i < 50; i++)
{
++DayOfWeek[r.Next(0,7)];
}
string output = null;
for(int ans=0; ans < 7; ans++)
output += DayOfWeek[ans] + "\n";
Console.WriteLine(output);
When I compile I am getting a lot of errors with the "++" , "<"
ect
Can Anyone help?
Thank
Rob
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 15 '05 #1
3 1291
BlueOysterCult <sc****@serv-dot-net.no-spam.invalid> wrote:
Hello
I am having dificulty with this homework question ( I know its
homework but I have been trying for a while with this)
"generate 50 random numbers between 0 and 6 and count the number of
occurences of each value. IT should employ the DAyOfWeek enumeration,
where 0 represents Sunday....."

public class DayOfWeek {
enum Days {Sat, Sun, Mon, Tue, Wed, Thu, Fri};

int[] DayOfWeek = new int[7];
Random r = new Random();
for(int i = 0; i < 50; i++)
{
++DayOfWeek[r.Next(0,7)];
}
string output = null;
for(int ans=0; ans < 7; ans++)
output += DayOfWeek[ans] + "\n";
Console.WriteLine(output);
When I compile I am getting a lot of errors with the "++" , "<"


Well, firstly I'm not sure why you've got your own Days enumeration
when you've been asked to use the DayOfWeek enumeration. You're then
calling one of your *variables* DayOfWeek, which doesn't seem like a
good idea.

However, most of the actual code is okay - it's just that you don't
have a method to put it in, and your braces don't match up.

(Personally I found the ++DayOfWeek[r.Next(0,7)]; syntax hard to
understand at first, but never mind.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
I didn't notice the Days vs DayOfWeek ---
Thanks

I guess I could use any variable name?

And oh, I do have a Method I just didn't include it in the post

Thanks for your help!!
R
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 15 '05 #3
BlueOysterCult <sc****@serv-dot-net.no-spam.invalid> wrote:
I didn't notice the Days vs DayOfWeek ---
I'm not suggesting that you change the enum name to DayOfWeek - I'm
suggesting that you use the one that .NET already provides.
I guess I could use any variable name?
Yes, but not using the name of another type would help to make the code
readable.
And oh, I do have a Method I just didn't include it in the post


That doesn't help much, then - in order to reproduce your compilation
error, we need to have the same code that you're trying to compile.
Please post a *complete* program (preferrably a short one that still
demonstrates the problem).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jack | last post by:
I have two files: sort_comparison.c++ my_sort.h sort_comparison.c++ calls this code in my_sort.h: void my_sort::fillArray(int arr,int n) { // const int random_number_range=1000000;
13
by: Roy Gourgi | last post by:
Hi, How do I invoke the random number generator that was suggested by a few people. Ideally, what I would like to do is to instantiate the random no. generator with a seed value that does not...
38
by: One Handed Man \( OHM - Terry Burns \) | last post by:
I have a basic question thats been niggling me, but I never found time to look at it before. If I have an enumeration such as this Fiend Enum TravelDirection North South East
12
by: Pascal | last post by:
hello and soory for my english here is the query :"how to split a string in a random way" I try my first shot in vb 2005 express and would like to split a number in several pieces in a random way...
14
by: avanti | last post by:
Hi, I need to generate random alphanumeric password strings for the users in my application using Javascript. Are there any links that will have pointers on the same? Thanks, Avanti
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.