954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

quadratic equation

[img]http://img19.imageshack.us/img19/9384/f5.JPG[/img]

#include
#include
void main()
{
double a,b,c,disc,x1,x2;
printf("To find the roots of a quadriatic equation with real roots\n")
disc=b*b-4*a*c
if(disc<0)
printf("The roots are complex",disc);
if(disc>=0)
printf("-b+sqrt(disc)/2a",x1);
printf("-b-sqrt(disc)/2a",x2);


This is what i wrote, i know it is missing alot
but I really dunno how to do it, so can anyone help me to do the rest
so it can run well

hkpkguy
Newbie Poster
5 posts since Jun 2004
Reputation Points: 11
Solved Threads: 0
 

Hello,

To start with, when you declare variables, initialize them right away:

double a = b = c = disc = x1 = x2 = 0.0;

Next, you will need to use cin or scanf to read the data into variables.

You will also need to check your operator precidence. Example:

4 * 3 / 4 + 6 = 9

4 * 3 / (4 + 6) = 4 * 3 / 10 = 1.2

Your disc equation will need help.

Let us know how it works.

Christian

kc0arf
Posting Virtuoso
Team Colleague
1,937 posts since Mar 2004
Reputation Points: 121
Solved Threads: 57
 

double a = b = c = disc = x1 = x2 = 0.0;

It uses equal? i dun get it?

scanf all variables?

hkpkguy
Newbie Poster
5 posts since Jun 2004
Reputation Points: 11
Solved Threads: 0
 

Hello,

double a = b = c = disc = x1 = x2 = 0.0;

declares all of those variables as double values, and then assigns them a value of zero.

Remember that in C, = is the assign operator, and == is the equals operator.

scanf(%d, variable); scans in an integer
scanf(%lf, variable); scans in a floating double number

You are going to need to read your C or C++ book to find out how to set these things up properly, and gain a greater understanding of what you are trying to do.

Give it a shot.

Christian

kc0arf
Posting Virtuoso
Team Colleague
1,937 posts since Mar 2004
Reputation Points: 121
Solved Threads: 57
 

Please dont post such huge pics,my connection is slow at the best and it take a long time to download huge pic :-(

FireNet
Posting Whiz in Training
258 posts since May 2004
Reputation Points: 108
Solved Threads: 7
 

Hello , this was my homework in the past
i hope it will help you

Attachments polynomial.cpp (3.19KB)
abu_sager
Newbie Poster
10 posts since Jun 2004
Reputation Points: 12
Solved Threads: 2
 
Please dont post such huge pics,my connection is slow at the best and it take a long time to download huge pic :-(

sorry about that

hkpkguy
Newbie Poster
5 posts since Jun 2004
Reputation Points: 11
Solved Threads: 0
 
Hello , this was my homework in the past i hope it will help you

urs is too hard for me

hkpkguy
Newbie Poster
5 posts since Jun 2004
Reputation Points: 11
Solved Threads: 0
 

This is my project thats due tomorrow
can someone do the rest for me?
i am lack of time now....
coz i got my final tomorrow too

hkpkguy
Newbie Poster
5 posts since Jun 2004
Reputation Points: 11
Solved Threads: 0
 
This is my project thats due tomorrow can someone do the rest for me? i am lack of time now.... coz i got my final tomorrow too


they dont do others homework here, your going to have to do it, best that you can hope for is a direction to go in, and maybe some hints, but you cant expect someone to just write all the code for you.

Killer_Typo
Master Poster
781 posts since Apr 2004
Reputation Points: 152
Solved Threads: 39
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You