BetaArchive Logo
Total Current Archive Size: 4765.54GB in 15409 files
Navigation Home Screenshots Image Uploader Server Info FTP Servers Wiki Forum RSS Feed Rules Please Donate
UP: 10d, 0h, 59m | CPU: 15% | MEM: 5694MB of 12279MB used
{The community for beta collectors}

Forum rules


Before you post, please make sure...

- ...you have first used Google to look for an answer, and you have asked other people you know via other methods (IM, e-mail, etc).
- ...your question has not been asked before. Search the forum first before posting.

If you meet those criteria, go ahead and post your question. Be sure to provide as much information you can about the problem and how to recreate it. Also provide information on hardware and software if applicable.


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPost subject: Need to randomize some things in c#.        Posted: Wed Nov 16, 2011 5:39 pm 
Amateur Beta Collector
Amateur Beta Collector
Offline

Joined
Sun Apr 11, 2010 8:48 am

Posts
99

Favourite OS
Archlinux
Hey betaarchive,

Well im doing something for school, some programming in C#, geography exactly. So I basiacally making an application that would test if you know the countries of World, which seemed not so hard in my head. :) So now I started and lets say I have lots of images with these countries I want, Africa for example, lets say I have one map in the window form and lots of countries in other images which are painted lets say red, and are placed exactly how they should show up. I make all these visible=false and they are all hidden. Now how could I go if I would want to do something like this: press Start - Random red country appears on scree, later on it validets if written name in textbox matches the one that should be and show if its either correct or incorrect, and if correct button next would randomize another random country... and so on.

If anyone has any ideas how should I go about this, I would be really really thankful. This thingy must be ready for next tuesday.

So, anyone? :P


Top  Profile
 PostPost subject: Re: Need to randomize some things in c#.        Posted: Wed Nov 16, 2011 7:47 pm 
Pro Beta Collector
Pro Beta Collector
User avatar
Offline

Joined
Sun Feb 01, 2009 4:04 pm

Posts
583

Location
Germany , Northrhine-Westphalia

Favourite OS
Windows 2000 Professional SP4
Hi,
currently I'm only Console but...
Make a random Number between 1 and 20 (when you have around 20 countries). Don't know the Command now. Then do a If or Switch, which check the Number. For every Number you can let appear something or else (I would use switch). To prevent the pogramm to use one number more times, write the Number in a session (or local) variable ,which is checked BEFORE If or Switch.
Use an Array for local Varible

_________________
Image


Top  Profile  WWW
 PostPost subject: Re: Need to randomize some things in c#.        Posted: Wed Nov 16, 2011 7:58 pm 
Amateur Beta Collector
Amateur Beta Collector
User avatar
Offline

Joined
Wed Jan 06, 2010 12:40 pm

Posts
134

Location
Germany
You can use a Dictionary<string,[...]> for this kind of stuff. Just pull out a random entry,store it in a local variable in the button_Click event handler, check whether the currently displayed image == entry.Value and entered text == entry.Key. Also displaying all images and hiding them from the very beginning is not very elegant, rather put them on the UI on a more dynamic way (when correct solution is give, pictureBox1.Image = ...)

EDIT: To get a random number between 0 and the dictionary's length, do "Random r = new Random(); int num = r.Next(countryDictionary.Count);"


Top  Profile
 PostPost subject: Re: Need to randomize some things in c#.        Posted: Wed Nov 16, 2011 8:38 pm 
Pro Beta Collector
Pro Beta Collector
Offline

Joined
Sat May 15, 2010 1:59 am

Posts
455

Location
Virginia, North America

Favourite OS
Longhorn 4074
Just making an assumption here but (C++ guy here, not a C#, sorry)

Code:
#include <ctime.h>

int main(int argc, char *argv[])
{
const int Elements = 5;
char *countries[Elements] = (char *);

/* or add your own form of loading the data into memory asides from hard coding it in, whatever */
countries[0] = "United States of America";
countries[1] = "Great Britian";
countries[2] = "Brazil";
countries[3] = "Canada";
countries[4] = "Jamacia";

srand((unsigned)time(0)); /* generate pseudo random numbers according to the current system time */

int x = 0;
while (x == 0)
{
printf("%s", countries[(rand()%Elements)+1]); /* select random country over and over again, modify for your own use, etc. this is just an example */
}
return 0;
}


_________________
Deus damnaret eam!


Top  Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 




Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

All views expressed in these forums are those of the author and do not necessarily represent the views of the BetaArchive site owner.

Powered by phpBB® Forum Software © phpBB Group

Copyright © 2006-2013

 

Sitemap | XML | RSS