c# - Quiz with polish and english months -


i'm doing simple quiz getting question "how called month xxx in polish?". i've done array list months, random taking month list, don't know how can check if typed month correct. ideas? here code i've done far;

random random = new random();             string[] miesiac = { "styczeŃ", "luty", "marzec", "kwiecieŃ", "maj", "czerwiec", "lipiec", "sierpieŃ", "wrzesieŃ", "paŹdziernik", "listopad", "grudzieŃ" }; //months in polish             string randommonth = (miesiac[random.next(12)]);             console.writeline("cześć, proszę powiedz mi jak jest " + randommonth + " po angielsku.");             string answer = console.readline(); 

and here stuck because not know how check if answer going correct or not. know have array list months in second language not know how check them because it's gonna random.

you can compare indexes. here approach generate month names:

var pl = new cultureinfo("pl-pl"); var en = new cultureinfo("en-gb"); var polishmonths = enumerable.range(1, 12).select(i => pl.datetimeformat.getmonthname(i)).toarray(); var englishmonths = enumerable.range(1, 12).select(i => en.datetimeformat.getmonthname(i)).toarray(); 

now can use array.findindex:

int polishindex = random.next(12); string randompolishmonth = polishmonths[polishindex]; string answer = console.readline(); int englishindex = array.findindex(englishmonths, m => string.compare(answer, m, true) == 0); bool iscorrect = englishindex == polishindex; 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -