![]() |
|
#1
|
||||
|
||||
Can't find logic errorThe code below creates a simple boolean output for determining the type of triangle you have based on the length of the sides, i.e. equilateral, isosceles, or scalene. The code works except for determining isosceles; if only 2 sides are the same length, all I'm told is that it's a triangle.
I've tried different ways of doing the AND/OR logic and using loops, switches, etc. Does anyone see my logic error? Thanks. CPP / C++ / C Code:
__________________
Common Sense v2.0-Striving to make the world a little bit smarter. |
|
#2
|
|||
|
|||
|
1. you have not initialized your boolean variables.
using uninitialized variables may cause your program to malfunction. also if you were to initialize your boolean variables to false, you would be able to get rid of those else statements where you define them to be false each time. 2. your triangle determination logic is flawed. type in 1 1 0 or 1 1 2 it shouldnt form a triangle, but it does. fix your statement. change the ORs to ANDs. 3. your isosceles triangle determination logic is flawed. a. Apparently when your triangle turns out to be equilateral, it's also an isosceles - do you want it to do that? b. you are checking for equilateral triangles in your isosceles statement. you need to change it to reflect the isosceles triangle properties: CPP / C++ / C Code:
__________________
spasms!!! |
|
#3
|
||||
|
||||
|
Thanks. I knew it was something easy, but I think I was "too close to the problem" to see how to fix it.
__________________
Common Sense v2.0-Striving to make the world a little bit smarter. |
Recent GIDBlog
Writing a book by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Operator Overloading: << | aaroncohn | C++ Forum | 36 | 07-Dec-2004 19:22 |
| Visual C++ 6 Compiler error | vip3r | C++ Forum | 2 | 13-Apr-2004 14:34 |
| Simple error that i cant find... irritating me | Homestar | C Programming Language | 8 | 30-Mar-2004 16:28 |
| [script] E-mail webmaster error page | BobbyDouglas | PHP Code Library | 0 | 19-Aug-2003 20:10 |
| 3 line sql querry causes error, but i cant find the raeson | norok | MySQL / PHP Forum | 2 | 01-Jul-2003 09:06 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The