Results 1 to 4 of 4
  1. #1
    ras_pari is offline Member
    Join Date
    Oct 2009
    Posts
    40
    Rep Power
    0

    Question need urgent help!!

    I have a code ..in which I am calling a function "return" which is returning a float variable ..but problem is that I have to return a value acoording to cross which is a is a integer variable .i. why I have use "if clause "for ex if cross ==1 then i have call a function name as "calculate1" it wiil return a float value that I have to pass this valve to the calling function "result".now the value which is reurning as "finalresult" is not access to the function result and error is coming:
    missing return statement;
    here is code:
    Java Code:
    float outputt=result(ch,df1,df2,df3,df4);
    public float  result(String crosses,String  number1,String  number2,String  number3,String  number4)
    {
    int mono=Integer.parseInt(number1);
    
    int mono1=Integer.parseInt(number2);
    
    int mono2=Integer.parseInt(number3);
    
    int mono3=Integer.parseInt(number4);
    
    int cross=Integer.parseInt(crosses);
      
    if (cross ==2)
    {
    
    float finalresult=calculate1(mono,mono1,mono2,mono3);
    System.out.println(finalresult);
    return finalresult;
    
    }
    
    if (cross ==3)
    {
    
    float finalresult=calculate2(mono,mono1,mono2,mono3);
    System.out.println(finalresult);
    return finalresult;
    }
    
    if (cross ==4)
    {
    
    float finalresult=calculate3(mono,mono1,mono2,mono3);
    System.out.println(finalresult);
    return finalresult;
    }
    
    if (cross ==5)
    {
    
    float finalresult=calculate4(mono,mono1,mono2,mono3);
    System.out.println(finalresult);
    return finalresult;
    }
    
    if (cross ==6)
    {
    
    float finalresult=calculate5(mono,mono1,mono2,mono3);
    System.out.println(finalresult);
    return finalresult;
    
    }
    
    if (cross ==7)
    {
    
    float finalresult=calculate6(mono,mono1,mono2,mono3);
    System.out.println(finalresult);
    return finalresult;
    }
    
    
    if (cross ==8)
    {
    
    float finalresult=calculate7(mono,mono1,mono2,mono3);
    System.out.println(finalresult);
    return finalresult;
    
    }
    
    
    }//at this line errror is coming as missing return statement
    finalresult is the float variable which I have to return in a result function...plz help me...:confused:

  2. #2
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    5

    Default

    all your return statemens are inside the if statement.

    What would happen if any of the if statements are applicable?

    and your code is a bit to the negative side.

    what you meant was may be

    if
    ...

    else if
    ..

    else if
    ..

    so on

    Why are redefining the same thing again and again instead

    Java Code:
    float outputt=result(ch,df1,df2,df3,df4);
    public float  result(String crosses,String  number1,String  number2,String  number3,String  number4)
    {
    int mono=Integer.parseInt(number1);
    
    int mono1=Integer.parseInt(number2);
    
    int mono2=Integer.parseInt(number3);
    
    int mono3=Integer.parseInt(number4);
    
    int cross=Integer.parseInt(crosses);
    
    
    float finalresult=calculate1(mono,mono1,mono2,mono3);  
    
    if (cross ==2)
    { 
          System.out.println(finalresult);
          return finalresult;
    
    }
    
    [B]else[/B]if (cross ==3)
    {
    
    System.out.println(finalresult);
    return finalresult;
    }
    
    [B]else[/B]if (cross ==4)
    {
    
    System.out.println(finalresult);
    return finalresult;
    }
    
    [B]else[/B]if (cross ==5)
    {
    
          System.out.println(finalresult);
          return finalresult;
    }
    
    [B]else[/B]if (cross ==6)
    {
    
             System.out.println(finalresult);
             return finalresult;
    
    }
    
    [B]else[/B]if (cross ==7)
    {
    
          System.out.println(finalresult);
           return finalresult;
    }
    
    
    [B]else[/B]if (cross ==8)
    {
    
             System.out.println(finalresult);
             return finalresult;
    
    }
     
    return _finalresult____;// MAY BE YOU CAN RETURN FINALRESULT HERE OR 
                                   // ANY OTHER RELEVANT FLOATT
    
    }//at this line errror is coming as missing return statement

  3. #3
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    6

    Default

    Java Code:
      public float  result(String crosses,String  number1,String  number2,String  number3,String  number4)
      {
      int mono=Integer.parseInt(number1);
    
      int mono1=Integer.parseInt(number2);
    
      int mono2=Integer.parseInt(number3);
    
      int mono3=Integer.parseInt(number4);
    
      int cross=Integer.parseInt(crosses);
       
      float finalResult = 0;
      
      switch (cross) {
        
        
        case 2:
          finalResult = calculate1(mono,mono1,mono2,mono3);
          break;
          
        case 3:
          finalResult = calculate2(mono,mono1,mono2,mono3);
          break;
    
        case 4:
          finalResult = calculate3(mono,mono1,mono2,mono3);
          break;
    
        case 5:
          finalResult = calculate4(mono,mono1,mono2,mono3);
          break;
    
        case 6:
          finalResult = calculate5(mono,mono1,mono2,mono3);
          break;
         
        case 7:
          finalResult = calculate6(mono,mono1,mono2,mono3);
    
        case 8:
          finalResult = calculate7(mono,mono1,mono2,mono3);
          break;
          
        default:
          System.out.println("unhandled cross: " + cross):
          break;
      } // switch(cross)
    
      System.out.println("finalResult for cross=" + cross + ": " + finalResult);
      return finalResult;
      }

  4. #4
    ras_pari is offline Member
    Join Date
    Oct 2009
    Posts
    40
    Rep Power
    0

    Default

    A big thanx to travishein....I now i got it ...........It is working....Thanx once again.

Similar Threads

  1. Urgent Help!!
    By Winniee in forum New To Java
    Replies: 5
    Last Post: 02-17-2009, 03:32 AM
  2. very urgent
    By nehaa in forum Networking
    Replies: 12
    Last Post: 01-23-2009, 05:46 PM
  3. Very Urgent
    By nehaa in forum AWT / Swing
    Replies: 6
    Last Post: 01-22-2009, 08:36 AM
  4. Urgent help
    By tiger100plus in forum New To Java
    Replies: 3
    Last Post: 12-09-2008, 05:10 AM
  5. please help urgent
    By ananas7777 in forum AWT / Swing
    Replies: 2
    Last Post: 12-25-2007, 08:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •