Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Programming C++ Project

  1. Feb 26, 2005 #1
    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 couldnt 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

    Attached Files:

  2. jcsd
  3. Feb 26, 2005 #2
    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.
  4. Feb 26, 2005 #3
    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...
  5. Feb 26, 2005 #4
    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.
  6. Feb 26, 2005 #5
    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"??
  7. Feb 26, 2005 #6
    Got it to ask for inputing the value for a...now I have another probelm...the approximate length isnt working right when i compare my sol'n w/ the samplecalc. Im 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.

    Attached Files:

    • C++.txt
      File size:
      4.1 KB
  8. Feb 27, 2005 #7
    someone plz help me out w/ this ASAP...thanks much
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook