C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2722
Number of posts: 5749

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
ERROR: Not all code paths return a vale Posted by visper007 on 26 May 2012 at 11:35 AM
the error is CalculateScore, BTW I'm a newbie in C#. this is a method from a game I'm working on. MasterMind.


public static long CalculateScore(byte chances, long millisec)
{
int score;
byte num1 = chances++;
byte num2 = (byte)10;
byte num3 = (byte)10;
switch (Program.currLevelIndex)
{
case (byte)7:
num2 = (byte)10;
break;
case (byte)11:
num2 = (byte)20;
break;
case (byte)15:
num2 = (byte)40;
break;
}

if ((int)chances >= 1 && (int)chances <= 3)
num1 = (byte)40;
else if ((int)chances >= 4 && (int)chances <= 6)
num1 = (byte)20;
else if ((int)chances > 7)
num1 = (byte)10;
if (millisec > 480000L)
num3 = (byte)10;
else if (millisec >= 240000L && millisec <= 480000L)
num3 = (byte)20;
else if (millisec < 240000L)
num3 = (byte)40;
try
{
score = Convert.ToInt32((int)num2 * (int)num1 * (int)num3);
}
catch (Exception ex)
{
score = 0;
}

Console.Clear();

Console.SetCursorPosition(Program.x, Program.y);
Console.Write("Your Score was: " + score);
}
Report
Re: ERROR: Not all code paths return a vale Posted by Funmilade on 29 May 2012 at 3:22 PM
Hi,

I must admit that I am unable to fully comprehend your code, since you did not include the Main method, and it looks somewhat scanty.

Looking at the signature of your method i.e.,

public static long CalculateScore(byte chances, long millisec) 


it is clear that all paths through the method must return a value of type long.

Please check the code to ensure all if-else, switch-case or other conditional statements always result in the method returning a value of type long.

Hope it helps.

Edward
Report
Re: ERROR: Not all code paths return a vale Posted by Funmilade on 29 May 2012 at 3:24 PM
Hi,

I must admit that I am unable to fully comprehend your code, since you did not include the Main method, and it looks somewhat scanty.

Looking at the signature of your method i.e.,

public static long CalculateScore(byte chances, long millisec) 


it is clear that all paths through the method must return a value of type long.

Please check the code to ensure all if-else, switch-case or other conditional statements always result in the method returning a value of type long.

Hope it helps.

Edward
Report
Re: ERROR: Not all code paths return a vale Posted by Funmilade on 29 May 2012 at 3:28 PM
Hi,

I must admit that I am unable to fully comprehend your code, since you did not include the Main method, and it looks somewhat scanty.

Looking at the signature of your method i.e.,

public static long CalculateScore(byte chances, long millisec) 


it is clear that all paths through the method must return a value of type long.

Please check the code to ensure all if-else, switch-case or other conditional statements always result in the method returning a value of type long.

Hope it helps.

Edward
Report
Re: ERROR: Not all code paths return a vale Posted by magnetsoftees on 17 Aug 2012 at 5:18 AM




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.