c# - Count how many times a specific mathematic equation is wrong, and display at the end -
basically i've created times table app. @ end of app, i've been able how many times got wrong, , how many times got right.
however want say:
you got:
6 x 4 wrong 6 times.
5 x 2 wrong 9 times.
etc...
rather got 20 correct, , 8 wrong.
so can see specific multiplications got wrong. know need add together code (under else statement). not sure how go this.
i thought best solution storing wrongs string in array, counting identical strings , outputting number. have no thought how this.
here's code:
namespace timestablesgame { class multiplication { random rng = new random(); int randomnumber; int randomnumbertables; int c = 0; int w = 0; int numberofgos = 0; int minrangetables; int maxrangetables; int minrange; int maxrange; public multiplication() { start: console.clear(); console.writeline("\nplease come in lowest number range practice times tables on: "); minrangetables = int.parse(console.readline()); console.writeline("\nplease come in higest number range practice times tables on: "); maxrangetables = int.parse(console.readline()); console.writeline("\nplease come in number of times play: "); numberofgos = int.parse(console.readline()); console.writeline("\nplease come in minimum range multiply by: "); minrange = int.parse(console.readline()); console.writeline("\nplease come in maximum range multiply by: "); maxrange = int.parse(console.readline()); repeat: console.clear(); (int = 1; <= numberofgos; i++) { randomnumbertables = rng.next(minrangetables, maxrangetables + 1); randomnumber = rng.next(minrange, maxrange + 1); console.write("\n\n{0}: {1} x {2} = ", i, randomnumbertables, randomnumber); if (randomnumbertables * randomnumber == int.parse(console.readline())) { console.writeline("correct"); c++; } else { console.writeline("wrong is: " + randomnumbertables * randomnumber); w++; } } console.writeline("\nyou right {0} times, , wrong {1} times.", c, w); console.readline(); console.writeline("would play again? type y yes new settings, r repeat using lastly settings, , other key exit."); char 1 time again = console.readkey().keychar; if (again == 'y') { c = 0; w = 0; goto start; } else if (again == 'r') { c = 0; w = 0; goto repeat; } } } }
i'd maintain track in dictionary....
resisting urge re-write goto stuff.....here's relatively simple way it:
dictionary<string, int> wrongs; //console questions... //begin looping logic wrongs = new dictionary<string, int>(); (int = 1; <= numberofgos; i++) { randomnumbertables = rng.next(minrangetables, maxrangetables + 1); randomnumber = rng.next(minrange, maxrange + 1); string eq = string.format("{0} x {1} = ", randomnumbertables, randomnumber); console.write("{0}: " + eq, i); if (randomnumbertables * randomnumber == int.parse(console.readline())) { console.writeline("correct"); c++; } else { console.writeline("wrong is: " + randomnumbertables * randomnumber); if (wrongs.any(x => x.key == eq)) { wrongs[eq]++; } else { wrongs.add(eq, 1); } w++; } } console.writeline("\nyou right {0} times, , wrong {1} times.", c, w); console.writeline("\n\nyou got:"); foreach (var item in wrongs) { console.writeline("{0} wrong {1} times", item.key, item.value); } //your logic repeat/restart
also....note not count "2 x 4" , "4 x 2" same equation....
also also....you can without using goto....please consider it.
c#
No comments:
Post a Comment