c# - why does it show me error that cost is an unassigned variable? -


console.writeline("enter sirial number of followin bevrege want buy"); console.writeline("beverge                     cost"); console.writeline("1.ness cafe                 2.25"); console.writeline("2.black coffe               2.25"); console.writeline("3.tea                       1.30"); console.writeline("4.hot choclate              2.50"); console.writeline("5.soup                      3.10"); console.writeline("6.coca cola                 3.30"); console.writeline("7.orange juice              3.20"); int sirial; sirial = int.parse(console.readline()); double mouny, cost; console.writeline("enter how ouny enterd machine "); mouny = double.parse(console.readline());       if (sirial == 1 || sirial == 2)         cost = 2.25;     if (sirial == 3)         cost = 1.30;     if (sirial == 4)         cost = 2.50;     if (sirial == 5)         cost = 3.10;     if (sirial == 6)         cost = 3.30;     if (sirial == 7)         cost = 3.20;   if (mouny == cost)     console.writeline(" n/ thank buying"); 

if user enters number other 1 through 7, cost not assigned value. can give initial value of 0 rid of compiler warning, add validation user enters valid option.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -