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

Click For Summary
SUMMARY

The discussion focuses on troubleshooting input issues in a C++ programming project, specifically regarding the input of a variable 'a'. The user initially struggles to prompt for 'a' while successfully obtaining inputs for 'theta1' and 'theta2'. Recommendations include using a do-while loop to ensure the input prompt executes at least once and avoiding old header files in favor of ISO standard headers. Additionally, the conversation highlights the importance of declaring the main function as 'int' rather than 'void' to avoid compiler issues.

PREREQUISITES
  • Basic understanding of C++ syntax and structure
  • Familiarity with loops, particularly do-while and while loops
  • Knowledge of function declaration and usage in C++
  • Understanding of ISO standard header files in C++
NEXT STEPS
  • Learn how to implement do-while loops in C++ for guaranteed input execution
  • Study the differences between old and new C++ header files and their implications
  • Explore function parameter passing techniques, particularly by value versus by reference
  • Investigate best practices for declaring the main function in C++
USEFUL FOR

C++ developers, programming students, and anyone troubleshooting input handling and function implementation in C++ projects.

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
 

Similar threads

  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
Replies
14
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 14 ·
Replies
14
Views
34K
Replies
9
Views
2K
  • · Replies 17 ·
Replies
17
Views
3K
Replies
40
Views
4K