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

  • SEARCH
  • Home
  • 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 8754277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:35:16+00:00 2026-06-13T13:35:16+00:00

The question is to write two solutions to the quadratic formula. One result is

  • 0

The question is to write two solutions to the quadratic formula. One result is when you use the plus operator in the formula and another when you use the negative operator.

My plan was to create two different methods calculating the different results of the formula with one method using the (+) and one using the (-). Then I want to call both those methods to display the results. The problem is when I call those methods in Eclipse it says there is an error “i cannot be resolved to a variable.” Is my solution to the problem right, am I missing anything and how can I fix the error?

import acm.program.*;

public class QuadraticFormula extends ConsoleProgram {

public void run(){
    println("Enter the coefficients for the quadratic equation: ");
    int a = readInt("Please enter the value of a: ");
    int b = readInt("Please enter the value of b: ");
    int c = readInt("Please enter the value of c: "); 



    println("Your first solution is" + QuadPlus(i));
    println("Your second solution is" + QuadMinus(i)); 

}



private double QuadPlus (double a, double b, double c, double x){
    double i = ((+(b)) + Math.sqrt(( b * b) - (4 * a * c)) / (2 * a));


    return i;

}

private double QuadMinus (double a, double b, double c, double x) {
    double i = ((-(b)) + Math.sqrt(( b *b) - (4 * a * c)) / ( 2 * a));

    return i; 
}

}

  • 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-13T13:35:17+00:00Added an answer on June 13, 2026 at 1:35 pm

    The line

    println("Your first solution is" + QuadPlus(i));
    

    Has two things wrong with it.

    1. It’s trying to reference a variable i that is local to a different method. Since i is out of the scope of the main method (the variables you declared called i are only in the scope of the QuadPlus and QuadMinus methods), eclipse can’t find a definition for i and so it’s throwing your error.

    2. The QuadPlus and QuadMinus methods are defined to take four double parameters each, so when you call them, you have to put four doubles in the parameter brackets. Otherwise, how would the program know what a, b, … etc are from just getting i?

    Your eventual call should look something like:

    println("Your first solution is" + QuadPlus(aDouble, bDouble, cDouble, xDouble));
    

    EDIT: You don’t actually seem to use the parameter x in your QuadThing methods, so you can just take it out of the definition, like:

    ... QuadPlus(double a, double b, double c) { ...
    

    And then have the call:

    QuadPlus(a, b, c);
    

    EDIT 2: Also,

    double i = ((+(b)) + Math.sqrt(( b * b) - (4 * a * c)) / (2 * a));
    

    … will divide only the square root by 2a, rather than the whole thing as in the quadratic formula. To fix it, move the last bracket before the slash divide. This applies to both methods.
    Lastly, the +/- part of the formula doesn’t affect the b in front; b is always (-b). The +/- is whether you plus or minus the square root:

    double plus = ( (-(b)) + Math.sqrt(( b * b) - (4 * a * c)) )  / (2 * a);
    double minus = ( (-(b)) - Math.sqrt(( b * b) - (4 * a * c)) )  / (2 * a);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was inspired by another question to write a script (or rather a one-liner)
Here is the question: write a method that swaps two variables. These two variables
Question: How would one write a function to check and return whether or not
Question simple and quick: I have started to use Netbeans to write some code
While trying to write an answer for another SO question something really peculiar happened.
I hope this question is not a RTFM one. I am trying to write
My question is pretty simple: How can I write a function once and make
This is just a question on how to write my code for a COM
I have a noobie question: I need to write SQL script that returns 3
My question is not clear at title [i can not write it exactly] e.g

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.