-1

so I'm running a program in java and I can't really find the main error this is my code:

public class Main { public static void main(String[] args) { double myCheck = 50.00; double yourCheck = 19.95; double fiinalRATE = 0.15; System.out.println("Tips are"); calcTip(myCheck); calcTip(yourCheck); public void calcTip(double bill); { tip = bill * fiinalRATE; System.out.println("The tip should be at least " + tip); } } 

and this is the error that I'm getting I think its the header but I don't really know what to put I'm kinda new at java though enter image description here

1
  • 1
    You need to define your method calcTip on the class level next to your main method, not inside it. Commented Jan 21, 2021 at 15:39

2 Answers 2

1

You can't declare function inside function. You have to pull function out from main() to the Main.class

Sign up to request clarification or add additional context in comments.

Comments

1

You cannot declare a method inside another method. So the compiler gets crazy :) Just move you calcTip() function outside main() function (after closing curly bracket of main() or before declaration of main()).

public class Main { public static void main(String[] args) { double myCheck = 50.00; double yourCheck = 19.95; double fiinalRATE = 0.15; System.out.println("Tips are"); calcTip(myCheck); calcTip(yourCheck); } public static void calcTip(double bill) { // fiinalRate must be declared as parameter of calcTip() // or as static field in Main class, // otherwise the code doesn't compile. double tip = bill * fiinalRATE; System.out.println("The tip should be at least " + tip); } } 

2 Comments

this doesn't compile since fiinalRATE is not known inside of calcTip
@f1sh you're right, as well as Gal Fudim who suggested edition with 'static' key-word for caclTip(). I'll edit

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.