Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8604179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:30:33+00:00 2026-06-12T02:30:33+00:00

I have a recursive function that will repeat the function until the if condition

  • 0

I have a recursive function that will repeat the function until the if condition is not met then output an integer. However the function outside this function that requires an integer is receiving a unit. How should I modify the code in order to return an int?

count(r,c,1,0)

   def count(r: Int, c: Int, countR: Int, lalaCount: Int): Int = {
    if (countR < (r + 1)) count(r,c,countR + 1, lalaCount + countR)
    else (lalaCount + c + 1)
   }

This is the whole program

object hw1 {
  def pascal(c: Int, r: Int): Int = {

   count(r,c,1,0)

   def count(r: Int, c: Int, countR: Int, lalaCount: Int): Int = {
    if (countR < (r + 1)) count(r,c,countR + 1, lalaCount + countR)
    else (lalaCount + c + 1)
   }
  } //On this line eclipse is saying "Multiple markers at this line
    //- type mismatch;  found   : Unit  required: Int
    //- type mismatch;  found   : Unit  required: Int
pascal(3,4)

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:30:35+00:00Added an answer on June 12, 2026 at 2:30 am

    The value returned from pascal is the last expression it contains. You want it to be your evaluation of count but that’s not the last thing. Assignments (def, val etc) are of type Unit, as you’ve discovered:

      def pascal(c: Int, r: Int): Int = {
    
       count(r,c,1,0) // => Int
    
       def count(r: Int, c: Int, countR: Int, lalaCount: Int): Int = {
        if (countR < (r + 1)) count(r,c,countR + 1, lalaCount + countR)
        else (lalaCount + c + 1)
       } // => Unit
      }
    

    Just move count(r,c,1,0) after the def and that should fix the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to make a recursive function that will compute the sum of the
Lets say I have a recursive function that creates lists within lists. It return
I have a simple recursive function RCompare() that calls a more complex function Compare()
Is it possible to have a PHP function that is both recursive and anonymous?
I have a simple recursive function to write in VBA that does the following
I'm trying to write a function that will dump a recursive tree of window
I have to make a recursive function that finds the number of ones from
I have a decorator that I wrote that will time a given function. It
I have a recursive function that uses ref to walk down a data structure
I need a recursive function that will find all controls on a page and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.