# What is wrong with my Code, can you all Check?

This is a discussion on What is wrong with my Code, can you all Check? within the C Programming forums, part of the General Programming Boards category; Whenever i try to run it, there's 3 erros but i don't know where, This is my first program and ...

1. ## What is wrong with my Code, can you all Check?

Whenever i try to run it, there's 3 erros but i don't know where, This is my first program and I'm new at this.

Write a C program that
Reads the coefficients (double a, b, c) of a quadratic equation a*x2..+..b*x..+..c..=..0
Computes the roots of that equation (if exist), and
Prints out an appropriate msg with roots (if any).
..
For example,
when a =0, we have a linear equation and we have only one root x=-c/b.
Compute d =....4*a*c - b2.
For d<0, we have two real roots,
For d=0, we have one root,
For d>0, we have no root

Code:
```#include<stdio.h>
#include<math.h>

int main(void)
{

/*Declare variables*/
double a, b, c, d;

/*Request Information from user*/
printf("Enter Value for a:");
scanf("%lf", &a);

printf("Enter Value for b:");
scanf("%lf", &b);

printf("Enter Value for c:");
scanf("%lf", &c);

/*Perform Calculations*/
printf("Equation: %fx^2 + %fx + c = 0\n", a, b, c);

if (a == 0)
{
printf("we have one root\n");
}
else
{
d = b * b - 4 * a * c;

if (d < 0)
{
printf("we have two real roots\n");
}
else if (d == 0)
{
printf("we have one root\n");
}
else if (d > 0)
{
printf("we have no root\n");

/*Exit Program*/
return 0;

}```

2. What errors?

4. }

These are the problems you will continue to have if you prefer not to INDENT YOUR CODE IN BLOCKS.

Also, one of your printf's has too many arguments.

5. have you tried a good indentation...???
your brackets arenot balanced you know...
take a look at the last elseif, at least you need 2 closing brackets there....

6. Originally Posted by MK27
}

These are the problems you will continue to have if you prefer not to INDENT YOUR CODE IN BLOCKS.

Also, one of your printf's has too many arguments.

I correct it the Indenting problem and now it runs.
When i run it and put the values for a, b, c and click enter so it can give me an answer, it closes, and doesn't give an answers, why.

7. Originally Posted by Cyberman86
I correct it the Indenting problem and now it runs.
When i run it and put the values for a, b, c and click enter so it can give me an answer, it closes, and doesn't give an answers, why.
Perhaps this is a segmentation fault, in which case you will need a debugger. However, it "worked" for me.

If you didn't write this code yourself and you are starting from scratch, it will be difficult for you to debug. It is also extremely unfinished, if you were (for example) expecting it to perform any calculations at all, so probably not worth bothering with if this is the case. You will be better off starting from scratch and writing something yourself.

To reiterate: This is a bad piece of code. If you wrote it, that's okay, don't be embarrassed or insulted! You might get it to work eventually. But if you didn't write it, throw it away now

8. Originally Posted by Cyberman86
I correct it the Indenting problem and now it runs.
When i run it and put the values for a, b, c and click enter so it can give me an answer, it closes, and doesn't give an answers, why.
maybe you could try to use

system( "pause" );

or

getch(); if you have conio.h

but if it's still not working maybe it is a segmentation fault.