Click here to Skip to main content
15,910,358 members
Home / Discussions / C#
   

C#

 
AnswerRe: Little Red 'X' on MDI Pin
Libor Tinka21-Oct-05 6:16
Libor Tinka21-Oct-05 6:16 
GeneralRe: Little Red 'X' on MDI Pin
Dwayner7921-Oct-05 7:37
Dwayner7921-Oct-05 7:37 
QuestionBeginner Help: Unassigned local variable Pin
ivelander21-Oct-05 4:19
ivelander21-Oct-05 4:19 
AnswerRe: Beginner Help: Unassigned local variable Pin
Member 114619621-Oct-05 4:34
Member 114619621-Oct-05 4:34 
GeneralRe: Beginner Help: Unassigned local variable Pin
ivelander21-Oct-05 4:41
ivelander21-Oct-05 4:41 
GeneralRe: Beginner Help: Unassigned local variable Pin
Matt Gerrans21-Oct-05 16:08
Matt Gerrans21-Oct-05 16:08 
AnswerRe: Beginner Help: Unassigned local variable Pin
Tom Larsen21-Oct-05 4:58
Tom Larsen21-Oct-05 4:58 
AnswerRe: Beginner Help: Unassigned local variable Pin
whizzs21-Oct-05 11:07
whizzs21-Oct-05 11:07 
Your problem is that it is possible in your if statement to never assign a value to finalSalary since you declared finalSalary at the beginning and did not initialize it. So if someone enters a "4" at your prompt the code will execute the final "else" statement and write out to the console "That is not a valid entry" but will continue on to the final Console.WriteLine which will try to execute with an uninitialized variable.

Visual studio is smart enough to detect when people try to initialize variables inside of "if" statements but not smart enough to know if all paths assign a valid result to the variable so it always throws a flag when you try to do this.

The answer is to do one of the following:
1) initialize the variable at instantiation
2) move the Console.WriteLine statement to inside each "if" clause that you want it to print the final salary (probably your best bet since you don't want it to write out if the users response is invalid)

Hope this helps
QuestionWriting a Trailware for an Application Pin
Samar Aarkotti21-Oct-05 4:18
Samar Aarkotti21-Oct-05 4:18 
AnswerRe: Writing a Trailware for an Application Pin
Tom Larsen21-Oct-05 4:54
Tom Larsen21-Oct-05 4:54 
GeneralRe: Writing a Trailware for an Application Pin
Samar Aarkotti21-Oct-05 5:22
Samar Aarkotti21-Oct-05 5:22 
GeneralRe: Writing a Trailware for an Application Pin
Tom Larsen21-Oct-05 8:09
Tom Larsen21-Oct-05 8:09 
GeneralRe: Writing a Trailware for an Application Pin
Samar Aarkotti21-Oct-05 8:26
Samar Aarkotti21-Oct-05 8:26 
GeneralRe: Writing a Trailware for an Application Pin
Tom Larsen21-Oct-05 10:55
Tom Larsen21-Oct-05 10:55 
GeneralRe: Writing a Trailware for an Application Pin
Samar Aarkotti22-Oct-05 6:06
Samar Aarkotti22-Oct-05 6:06 
GeneralRe: Writing a Trailware for an Application Pin
Samar Aarkotti22-Oct-05 7:35
Samar Aarkotti22-Oct-05 7:35 
QuestionHow to save a hotkey assignment Pin
mav.northwind21-Oct-05 3:54
mav.northwind21-Oct-05 3:54 
AnswerRe: How to save a hotkey assignment Pin
sebastud21-Oct-05 7:20
sebastud21-Oct-05 7:20 
GeneralRe: How to save a hotkey assignment Pin
mav.northwind21-Oct-05 23:39
mav.northwind21-Oct-05 23:39 
QuestionRemoting server crashes when client quits Pin
polisen21-Oct-05 3:53
polisen21-Oct-05 3:53 
AnswerRe: Remoting server crashes when client quits Pin
Tom Larsen21-Oct-05 5:01
Tom Larsen21-Oct-05 5:01 
GeneralRe: Remoting server crashes when client quits Pin
polisen21-Oct-05 6:28
polisen21-Oct-05 6:28 
AnswerRe: Remoting server crashes when client quits Pin
Rob Graham21-Oct-05 8:02
Rob Graham21-Oct-05 8:02 
GeneralRe: Remoting server crashes when client quits Pin
Anonymous21-Oct-05 8:06
Anonymous21-Oct-05 8:06 
QuestionScroll A Control Manually Pin
Ali Beirami21-Oct-05 3:06
Ali Beirami21-Oct-05 3:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.