visual studio - c# console application unassigned local variable -
this question has answer here:
int valueone, valuetwo, numchar, total; console.writeline("this program doing of 4 mathematical proccesses"); console.writeline("you can add , substract , divide , multiply"); console.writeline("when asked please type values or proccesses want."); console.writeline("please type first value"); valueone = convert.toint32((console.readline())); console.writeline("please type second value"); valuetwo = convert.toint32((console.readline())); console.writeline("please enter number of proccess/character want meaning (1 = +) , (2 = -) , (3 = *) , (4 = /)"); numchar = convert.toint32((console.readline())); if (numchar == 1) total = valueone + valuetwo; if (numchar == 2) total = valueone + valuetwo; if (numchar == 3) total = valueone * valuetwo; if (numchar == 4) total = valueone / valuetwo; console.writeline("the total :"); console.writeline(total); console.readline(); the console.writeline(total); @ end apparently unassigned local variable , though should assigned lines beneath "if" lines, note i'm new in visual studio , started taking courses , , don't think duplicate because other post's fix didn't work me.
let's code didn't produce error, , compiled , ran. think happen if numchar wasn't 1, 2, 3, or 4?
your code never reach of statements in ifs there, , never assign initial value total. since entirely possible given program (and impossible check in general -- see halting problem), error substantiated , necessary.
Comments
Post a Comment