| | |
Triangular number calculator
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Mar 2007
Posts: 12
Reputation:
Solved Threads: 0
Can anyone spot the semantic error in this triangular number calculator here? It correctly reports 21 as being a triangle number but incorrectly that 15 is not a triangle number. However if you input 15 as the first value entered it correctly says that 15 is a triangle number!!
C Syntax (Toggle Plain Text)
int main(int argc, char* argv[]) { int Number; int Index; char Again; Index = 1; Again = 'y'; while (Again == 'y') { Number = ReadIntPr("Enter number for testing: "); while (Index*(Index+1) < 2*Number) { Index = Index + 1; //'i' was used rather than index here } if (Index*(Index+1) == 2*Number) //the correct 'is equal to' was not used WriteStringCr("Triangular"); else WriteStringCr("Not triangular"); //the semicolon here was not included Again = ReadCharPr("Test another number (y/n)? "); } getchar(); return 0; }
Last edited by afr02hrs; Mar 31st, 2007 at 12:20 pm.
•
•
•
•
Can anyone spot the semantic error in this triangular number calculator here?
C Syntax (Toggle Plain Text)
ReadIntPr("Enter number for testing: "); WriteStringCr("Triangular"); Again = ReadCharPr("Test another number (y/n)? "); }
Are you including the proper #defines at the beginning of the source file?.
Are you providing the proper prototypes for those functions.
Did you include those functions?.
"If it moves, tax it. If it keeps moving, regulate it, and if it stops moving, subsidize it" - Ronald Reagan
![]() |
Other Threads in the C Forum
- Previous Thread: very large ints
- Next Thread: How to create a Windows HOOK
Views: 2621 | Replies: 11
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays bash binarysearch changingto char character cm copyanyfile copypdffile createprocess() database directory drawing dynamic execv feet fgets file floatingpointvalidation fork framework function functions getlogicaldrivestrin givemetehcodez global grade graphics gtkwinlinux histogram homework i/o ide include infiniteloop initialization input interest intmain() iso keyboard kilometer lazy license linked linkedlist linux list looping loopinsideloop. lowest matrix meter microsoft mqqueue mysql oddnumber odf open openwebfoundation overwrite pause pdf pointer pointers posix power process program programming pyramidusingturboccodes read recursion recv recvblocked reversing segmentationfault single socket socketprogramming spoonfeeding standard strchr string student suggestions system test testing threads unix urboc user whythiscodecausesegmentationfault win32api windowsapi






