I am having trouble with this program in the if else part
I feel that is a really simple problem, I have tried 'else if' as well as 'else' but all sorts of errors come up.

#include <stdlib.h>
#include <iostream>
using namespace std;

int main()
{
	double a, b, c;

	cout <<"Input value for a" <<endl;
		cin >>a;
	cout <<"Input value for b" <<endl;
		cin >>b;
	cout <<"Input value for c" <<endl;
		cin >>c;

//////////////////////////////////////////////
		//LOOP
		double discriminant = ((pow(b,2))-4*a*c);
	if (a==0)
	{
			if(b==0)
				{cout <<"No solution.";}
			else 
			{cout <<"One real solution.";}
	}
	else{
		if (discriminant>0);
		{cout <<"Two real unequal solutions.";}
		else if
			{if (discriminant==0)
			{cout <<"Two real equal answers.";}
			else	
			{cout <<"Two complex conjugate solutions.";}
		}
	}
	system ("pause");
		return 0;
}

Recommended Answers

All 3 Replies

It looks to me like you have an extra "if" and an extra pair of { } in line 30.

That is, lines 29-30 should read

else if (discriminant==0)

27 has an extra semicolon that doesn't belong either.

Consistent formatting would help to highlight these problems.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.