![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
::Need help Please:: using If & Switch in Quadratic equation.i need help for this program.
in the following program, i need help using switch, so that i could choose all the possible roots for the program. such as 1) real roots 2) imaginary roots 3) repeated roots 4) exits (default) the program. CPP / C++ / C Code:
Last edited by internetbug : 07-Apr-2005 at 15:36.
Reason: Please insert your C code between [c] & [/c] tags
|
|
#2
|
|||
|
|||
|
Need three choices for the switch:
1) real roots 2) imaginary roots 3) repeated roots 4) exits (default) |
|
#3
|
||||
|
||||
|
Hello,
The switch statement The switch statement is a multi-way decision that tests whether an expression matches one of a number or constant integer values, and branches accordingly: CPP / C++ / C Code:
Each case is labeled by one or more integer-valued constant expressions. If a case matches the expression value, execution starts at that case. All case expressions must be different. The case labeled default is executed if none of the other cases are satisfied. A default is optional; if it isn't there and if none of the cases match, no action at all takes place. Cases and the default clause can occur in any order. The break statement causes an immediate exit from the switch. Because cases serve just a labels, after the code or one case is done, execution falls through to the next unless you take explicit action to escape. break and return are the most common ways to leave a switch. A break statement can also be used to force an immediate exit from while, for, and do loops. Here's an example of using a switch statement in your program: CPP / C++ / C Code:
I didn't add the Repeated roots function, so you can have something to do. I also split the program into different functions. If you have questions, please feel free to ask. - Stack Overflow __________________
Following the rules will ensure you get a prompt answer to your question. If posting code, please include BB [C] / [C++] tags. Your question may have been asked before, try the search facility. |
|
#4
|
|||
|
|||
|
Quote:
If a is equal to zero, it's not a quadratic equation and you have handled that. For a not equal to zero,your conditional statements (d < 0), (d == 0), and (d > 0), tell you whether there are complex roots, repeated real roots, and distinct real roots, respectively. Why do you think you need a switch statement? What value would that add to your program? Regards, Dave |
|
#5
|
|||
|
|||
|
Quote:
How is the user supposed to know the type of roots his equation has? What if he gives the coefficients for an equation that has complex roots, but tells the program to find real roots (or vice versa)? Shouldn't the program at least check before trying to take the square root of a negative number? But, wait a minute: if the program can check to see whether the roots are real or complex, then why make the user tell it in the first place? I guess I missed the point. Regards, Dave |
|
#6
|
|||
|
|||
|
Quote:
you are right. but this is a Hw problem, and i really needed help using switch statements, cause we had to use switch statements for this problem, to make a choice kind a problem. thank you Stack overflow for the help. it works. |
|
#7
|
|||
|
|||
|
Quote:
At least I was correct in my response to Stack Overflow: Quote:
Sorry. Regards, Dave |
Recent GIDBlog
Stupid Management Policies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problems with switch statement | dontcare | C++ Forum | 4 | 29-Nov-2004 19:28 |
| problem with switch case | if13121 | C Programming Language | 3 | 22-Nov-2004 22:26 |
| Re: Command Line Arguments, Part 1 | WaltP | C Programming Language | 0 | 11-Jul-2004 00:34 |
| Help a C++ Idiot: I am trying to fill an array based on a switch statement. | Psycop | C Programming Language | 2 | 14-Apr-2004 04:12 |
| Microsoft Equation | conkermaniac | Computer Software Forum - Windows | 1 | 15-Feb-2003 12:03 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The