c# - How do I split an array into two different arrays and also, how do i allow the user to only enter in part of the array and not the maximum amount? -
i can't figure out how split array correctly can pass 2 separate arrays multiple different methods. end array @ point without program giving user error. can give me direction on , me fix program?
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; namespace proj09lea { class program { // declare constant integer const int max = 10; static void main(string[] args) { // declare , array of integers int[] array = new int[max]; console.writeline("\nsaturday coder's bowling team"); console.writeline("enter in name , score each person on team."); console.writeline("for example, mary 143. hit enter when done.\n"); // fill array user input (int = 0; < array.length; i++) { // ask user enter data console.writeline("enter in name , score: "); // line of data input user stored here string userinput = console.readline(); // userinput split 2 pieces, stored in array string[] parsedinput; // line splits string userinput 2 pieces parsedinput = userinput.split(); // store first piece, name, in string array string names = parsedinput[0]; // store second piece, score, in integer variable int scores = int.parse(parsedinput[1]); array[i] = scores; } console.writeline("------------ input complete ------------\n"); console.writeline("here scores game:"); // display scores each person method displayscores displayscore(array); // display highest score , name of player method highscore highscore(array); // display lowest score , name of player method lowscore lowscore(array); // display average score method averagescore averagescore(array); console.writeline("press enter continue. . ."); console.readline(); } static void displayscore(int[] array) { (int = 0; < array.length; i++) { console.writeline("{0}'s score {0}.\n", array[i]); } } static void highscore(int[] array) { int max = array.max(); console.writeline("congratulations {0}, score of {0} highest.", max); } static void lowscore(int[] array) { int min = array.min(); console.writeline("{0}, score of {0} lowest. better practice.", min); } static void averagescore(int[] array) { int sum = array.sum(); int average = sum / array.length; console.writeline("the average score game {0:d}.", average); } } }
if willing input inputs 1 one first name after scores 1 one
console.writeline("enter in name: "); string userinput = console.readline(); (int = 0; < array.length; i++) { console.writeline("enter in score "+i+": "); string score = console.readline(); // store second piece, score, in integer variable int scores = int.parse(score); array[i] = scores; }
Comments
Post a Comment