c# - getting unassigned variable error on a variable that is assigned -
userInput
is assigned, so I'm not sure why I get the error I already He has tricked through the same questions, Gog, Benges and I did not know what I wanted. Ps for programming new
static zero main (string [] args) // // declared variable int hour, minute, second, balance, user input; Const int SECONDS_PER_MINUTE = 60; Const int SECONDS_PER_HOUR = 3600; UserInput = getUserInput (userInput); // Error hour = Calculate (user input, SECONDS_PER_HOUR); Balance = count dimension (user input, SECONDS_PER_HOUR); Minutes = calculated end (remaining, SECONDS_PER_MINUTE); Seconds = calculate seconds (balance, SECONDS_PER_MINUTE); DisplayResults (hours, minutes, seconds, user input, seconds); } / / URI indicates to enter the constant number of users, static static int getUserInput (int userInput) {Console.WriteLine ("How about you enter several seconds" and sick I can see that I What can I do for you.);); Return userInput = int.Parse (Console.ReadLine ()); } // This method moves to userinput and converts for hours if necessary. // user input / secondends / NAHOR will be returned for calculation // stored in main and variable variables. The same goes for the rest / which includes the display rolls Public Static Introlhorse (Int User Input, Int SeeksApraHOR). User input / secondendsfarr; } // This method takes the userinput and calculates the remaining public static internet for minutes and seconds (int user input, int SECONDS_PER_HOUR) {user input% SECONDS_PER_HOUR; } Calculation of public static internet (complete balance, int SECONDS_PER_MINUTE) {Remaining balance / SECONDS_PER_MINUTE; } Public static intranetic second (int balance, int SECONDS_PER_MINUTE) {left remaining% SECONDS_PER_MINUTE; }
Here is the problem code:
userInput = GetUserInput (userInput);
User input
is assigned after , but think of it like this:
int tmp = getUserInput (userInput); UserInput = tmp;
Nothing has been assigned the value userInput
before for the call method. It is not clear why you are specifying a parameter honestly - you are not actually using it code cleaner:
int userInput = GetUserInput (); ... public static GetUserInput () {Console.WriteLine ("..."); Return int.Parse (Console.ReadLine ()); }
Note how I am declaring the variable at first point of use - it is generally good idea, in addition to this, it will be cleaner if you stabilize your method declare ... and use within your calculation *
methods (how do you want to parameter the method continuously?). Your main
method will be clear as follows:
const intslinesPerMinute = 60; Const int seconds on = hoars = seconds; * 60; Static zero main (string [] args) {int userInput = GetUserInput (); Int hours = count (user input); Int balance = Calculatemen (user input); Int Minute = Quantities calculated (left); Int seconds = calculate seconds (balance); DisplayResult (hours, minutes, seconds, user input, seconds); }
(I think that changing the order of the DisplayResults parameter
suggests, along with some other things, but it is probably just enough. )
Comments
Post a Comment