Can anyone spot the semantic error in this triangular number calculator here?
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?.
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
Index = 1;
should be inside the outer while loop.
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
Index = 1;
should be inside the outer while loop.
I'm afraid that is not correct. Index is a counter and is ok were is being declared.
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
I guess I'm not understanding what your saying.
Where did you change the Index = 1 to?.
... Is it working now?.
Could you post your changes?.
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
You keep editing your original question. Is is very confusing. You has changed you question three times.
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
Hi Edited the question once. Not changed in over an hour.
The first time you original question was about a specific line error that you had. You wrote:Again = ReadCharPr("Test another number (y/n)? "); //statement missing here?
Second time you question was edit again and also you included this:
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)? ");
And after that you edited the question to: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!!
No desire to start a war of words here. But like I say. You want help,
you will get help here, however editing post to different questions are
confusing.
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
I guess I'm not understanding what your saying.
Where did you change the Index = 1 to?.
Rereadvijayan's post. If the OP did what was suggested, it should be very clear where the assignment was placed:
Index = 1;
should be inside the outer while loop.
I'm afraid that is not correct. Index is a counter and is ok were is being declared.
There's nothing wrong with initializing it every iteration; in fact the lack of doing so is what caused the problems.
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339