Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

No such file or directory error

+6 votes
asked Apr 20, 2023 by Caleb Murnan (230 points)
I'm still learning classes in C++ and I don't understand this error that I'm getting from `#include QuadraticEquation`. Here's my code:

#include <iostream>
#include <cmath>
#include "QuadraticEquation"
using namespace std;

class QuadraticEquation{
private:
    double a = 0, b = 0, c = 0;
public:
    QuadraticEquation(double a, double b, double c)
    {
        this-> a = a;
        this-> b = b;
        this-> c = c;
    }
    double getA(){
        return a;
    }
    double getB(){
        return b;
    }
    double getC(){
        return c;
    }
    
    double getDiscriminant(){
        return (pow(b, 2) - 4 * a * c);
    }
    
    double getRoot1(){
        return ((-b + sqrt(pow(b, 2) - 4 * a * c)) / (2 * a));
    }
    double getRoot2(){
        return ((-b - sqrt(pow(b, 2) - 4 * a * c)) / (2 * a));
    }
};

int main()
{
    double a = 0, b = 0, c = 0;
    //User enters values for a, b, and c.
    cout << "Enter the values for a, b, and c: ";
    cin >> a >> b >> c;
    
    //Object created.
    QuadraticEquation q1 (a, b, c);
    
    if (q1.getDiscriminant() > 0){
        cout << "Root 1: " << q1.getRoot1() << ", Root 2: " << q1.getRoot2() << endl;
        //Two Roots
    }else if (q1.getDiscriminant() == 0){
        //One root
        cout << "Root 1: " << q1.getRoot1() << endl;
    }else{
        //No roots
        cout << "The equation has no real roots." << endl;
    }
}

1 Answer

+1 vote
answered Apr 20, 2023 by Peter Minarik (88,520 points)
selected Apr 20, 2023 by Caleb Murnan
 
Best answer

You do not have a file called QuadraticEquation. If you remove the line

#include "QuadraticEquation"

your code compiles and runs.

commented Apr 20, 2023 by Caleb Murnan (230 points)
So the only time I'll ever use `#include "QuadraticEquation"` is if I use the class in a seperate file from main?
commented Apr 20, 2023 by Peter Minarik (88,520 points)
Something like that. :)
commented Apr 20, 2023 by Caleb Murnan (230 points)
Thank you for your help:)
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...