not all code paths return a value, and need to get 2 variables out of a method -


i'm trying newa , newc out of method gives me error. don't know how separate numbers if come out of method please help, still newbie :( far code gets 3 numbers user. put them method , need take away newa , newc , store them in separate variables.

namespace factorising_quadratic_expressions {     class program     {     static void main(string[] args)     {         int divideby = 0;         console.writeline("the form ax^2 + bx + c"); // of part of working out.         console.writeline("write down ");         int = convert.toint32(console.readline());         console.writeline("write down b ");         int b = convert.toint32(console.readline());         console.writeline("write down c ");         int c = convert.toint32(console.readline());         int num = * c;         g(num, b, divideby); // need make 2 variables newa , newc here     }     public static int g(int num01, int num02, int num03)     {         int x = 0;         while (x == 0)         {             if (num03 > 20)             {                 console.writeline("this not possible factorise");                 x = x + 1;             }             num03 = num03 + 1;             int newa = num01 / num03; //calculations done newc , newa             int newc = num03;             if (newa + newc == num02)             {                 x = x + 1;             }             else if (newa - newc == num02)             {                 x = x + 1;             }             else if (newc - newa == num02)             {                 x = x + 1;             }             num01 = newc;  //me failing @ trying return them             num03 = newa;             return num01; return num02; return num03;               }         }     } } 

this because have no return value outside of while statement. compiler thinks there potentially case x !== 0 , while loop skipped. function supposed return int, cause error.

try putting return -1; after while loop (or other number let know function had error.

also, there no need multiple return statements @ bottom of g() function. once gets first return statement return number , no code after run.

if you're trying print out answer screen, can make g() function void function , not return anything. right in main function, aren't doing return values g() anyway.

here's how write g() function:

public void g(int num01, int num02, int num03) {     if (num03 > 20)     {         console.writeline("this not possible factorise");         return;     }      num03 = num03 + 1;     int newa = num01 / num03;     int newc = num03;      if (newa + newc == num02)     {         return;     }      if (newa - newc == num02)     {         return;     }      if (newc - newa == num02)     {         return;     }      // we've got error cases taken care of,     // can math here , use console.writeline     // print out screen.      return; } 

my apologies if have syntax errors in there. wrote memory , didn't try compiling it.


Comments