Overloaded Method. Invalid elements error.

0 Cardinal Coog · June 28, 2015
In the call to the function, I want to be able to replace "subTotal" and "taxRate" with actual numbers rather than initializing the variables with numbers when they're declared .  Please see the comment. 

Why can't I do this?

Thanks for any help.

Code that works:



Using UnityEngine;
using System.Collections;

public class Practice : MonoBehaviour 
{

public float tax;
public float taxRate = .0825f;
public float subTotal = 20.00f;


// Use this for initialization
void Start () 
{

}

void Update ()
{
if (Input.GetKeyDown (KeyCode.Space)) 
{
tax = TaxFinder(subTotal, taxRate); //Want to replace w/ (20.00, .0825)
Debug.Log ("Tax: " + tax);
}
}


public float TaxFinder(float subTotal, float taxRate)
{
return (subTotal * taxRate);

}


}


Post a Reply

Replies

Oldest  Newest  Rating
0 Alper Akgoz · July 6, 2015
You're welcome :)
0 Cardinal Coog · June 30, 2015
Thanks, Alper. 

I just noticed that a few minutes ago. I added the "f" and it works. So very, very easy to overlook something so small. It's enough to drive a person insane...:(

Thanks again!:)
0 Alper Akgoz · June 29, 2015
Did you try 20.00f and 0.0825f ?
0 Cardinal Coog · June 28, 2015
Here's the code that doesn't work. (The error doesn't show when I paste the code here for some reason.)

"The best overloaded method match for 'Practice.TaxFinder(float, float)' has some invalid arguments"

using UnityEngine;
using System.Collections;

public class Practice : MonoBehaviour 
{

public float tax;
public float taxRate;
public float subTotal;


// Use this for initialization
void Start () 
{

}

void Update ()
{
if (Input.GetKeyDown (KeyCode.Space)) 
{
tax = TaxFinder(20.00, 0.0825);
Debug.Log ("Tax: " + tax);
}
}


public float TaxFinder(float subTotal, float taxRate)
{
return (subTotal * taxRate);

}


}
  • 1

C#

107,245 followers
About

C# is an object-oriented language designed for improving the development of web applications.

Links
Moderators