Troubleshooting C++ Code: How to Fix Input Issues in a Programming Project

AI Thread Summary
The discussion focuses on troubleshooting input issues in a C++ project, specifically regarding the inability to prompt for a variable "a" while successfully obtaining inputs for "theta1" and "theta2." Suggestions include using a do-while loop to ensure the input prompt executes at least once, as the current while loop condition may prevent it from running. There are recommendations to avoid outdated header files and to pass values by reference for better code efficiency. Additionally, concerns are raised about the accuracy of the approximate length calculation and the need for a function to compute this length using specified intervals. The user seeks urgent assistance to resolve these programming challenges.
hytuoc
Messages
26
Reaction score
0
I am working on a project, I am attaching my code and the Solutions...im not sure wat is wrong w/ the code, but i couldn't get it to ask for "Inputting a value for a" at all...i was able to get it to input theta1 and theta2 though. Plz help me out ASAP...I want to attach my assignment pages along w/ this but the file is too big...
Thanks so much
 

Attachments

Physics news on Phys.org
Surely that while loop isn't going to run, since a is neither less than 0.25 or greater than 1 initially? I've only done a little bit of C++, so I can't remember if it has a do-while loop (though I expect it does), where you can get the loop to run at least once. It sounds like you should use that instead of while.
 
Ahh! Don't use the old *.h including files. Use the new ISO headfiles. The old name, whitout the ending ".h".

Actually I don't have enough time to understand your algorithm...

But that option function looks quite nasty to me. Just pass the chosen number by value istead is my recommdation...

Personally, I don't like do-while loops, and Code Complete advise you to not use them, but in this case the use of them is justified...
 
Also, aren't you technically meant to declare main() as int in C++? I've heard some compilers don't like when you use void.
 
Nylex said:
Surely that while loop isn't going to run, since a is neither less than 0.25 or greater than 1 initially? I've only done a little bit of C++, so I can't remember if it has a do-while loop (though I expect it does), where you can get the loop to run at least once. It sounds like you should use that instead of while.
inputing a, I did the same thing to ask for input for theta1 and theta2...how come it work fine for those put not for "a"??
 
Got it to ask for inputing the value for a...now I have another probelm...the approximate length isn't working right when i compare my sol'n w/ the samplecalc. I am attaching my updated code along w/ this message
I have to write a program that compute the arc length : "A segment of the curve can b divided into intervals and a chord to the curve draqn in each interval. The approximate length of the segment is obtained by adding up the lenghts of the chords. The accuracy of the result is a function of the number of intervals used. Increasing the number of the chords increases the accuracy, but only up to a point. The computation is to be terminated when the use of a larger number of intervals produces a negligible change in the result."
and there is one part I that i have to do...but not sure how:
Call function approx to compute aplen, the approximate value of the length. Use n=4 intervals for the first approximation. Repeat the computaion up to 10 times, doubling the value of n each time, as long as successive length values are increasing, and differences between successive values are decreasing and are greater than .01 percent(%) of the approximate value.
 

Attachments

someone please help me out w/ this ASAP...thanks much
 
Back
Top