My quadratic equation program won't execute

So, for the exercise where you write a program that solves the quadratic equation, my program won’t execute. I know the code has no bugs because I copied it into another coding website that runs C++ and it worked fine, so I’m not sure why it won’t work here. Here’s the code:


int main() {

double a, b, c;

std::cout << “Enter a: \n”;
std::cin >> a;

std::cout << “Enter b: \n”;
std::cin >> b;

std::cout << “Enter c: \n”;
std::cin >> c;

double root1, root2;

root1 = (-b + std::sqrt(bb - 4ac)) / (2a);

root2 = (-b - std::sqrt(bb - 4ac)) / (2a);

std::cout << "root 1 = " << root1 << " and root 2 = " << root2 << “\n”;

return 0;


It lets me compile the program, but when I try to execute it after it never gives the prompt to enter a value for a. Can anyone help?

Hello, @beta5554413037. Welcome to the forum!
Your code as you’ve posted it is incomplete:

The reason is that it isn’t properly formatted for a post in the forum. Any time you need to post code please follow these instructions:

If you will reply with your code formatted using the </> button, and include a link to the specific exercise you are working on, I’ll see what I can do.

1 Like

Besides the missing includes, copy and pasting code could cause issues with ascii characters not being recognized especially double quotes. Furthermore just because it was on a coding website doesn’t at all mean that it is correct, efficient or safe.

(bb - 4ac)) / (2a);
That bit of code looks absolutely wrong


The markup for the forum converts what is between the *'s to itallics, and you don’t see the *'s. They are there.


@beta5554413037, proper formatting for the forum aside, your code does work when I run it in the Codecademy project. Is it possible that you didn’t click Save prior to compiling?

1 Like

Sorry about the mistakes with the formatting, I’m new here.

Anyway, that’s what I was forgetting. Thanks!


No worries. That bit about formatting is more FYI for future posts where the code may be more complex. Happy coding!

1 Like