Tuesday, 15 April 2014

c# - Local variable name 'choice' cannot be declared because it would give different meaning to 'choice' -



c# - Local variable name 'choice' cannot be declared because it would give different meaning to 'choice' -

sorry, i'm new programming world. i'm creating console application takes input on whether want convert celsius fahrenheit or vice-versa.

the problem i'm running is:

"error 3 local variable named 'choice' cannot declared in scope because give different meaning 'choice', used in 'parent or current' scope denote else"

i tried looking @ other examples, far more complicated brain can understand now.

namespace temperatureapp { class programme { static void main(string[] args) { int choice; { console.writeline("hi! temperatue app"); console.writeline("press 1 c f or 2 f c"); //take user input int selection = convert.toint32(console.readline()); if (choice == 1) { console.writeline("great, chose c f. come in temp."); int celcius = convert.toint32(console.readline()); //next line utilize formula , show reply } if (choice == 2) { console.writeline("great, chose f c. come in temp."); int fahrenheit = convert.toint32(console.readline()); //next line utilize formula , show reply } else console.writeline("that not right choice."); //in way, maintain asking person either 1 or 2 } while (choice != 1 || selection != 2); console.readline(); } } }

int selection = convert.toint32(console.readline());

should read

choice = convert.toint32(console.readline());

by putting int in sec time, declaring variable called "choice" within {}. definition conflicting 1 outside.

c# if-statement while-loop do-while

No comments:

Post a Comment