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

In summary, the code is not asking for inputting a value for "a". I was able to input theta1 and theta2 though.
  • #1
hytuoc
26
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

  • C++.txt
    4.1 KB · Views: 407
  • sample calc.doc
    36 KB · Views: 200
Physics news on Phys.org
  • #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.
 
  • #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...
 
  • #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.
 
  • #5
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"??
 
  • #6
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

  • C++.txt
    4.1 KB · Views: 366
  • #7
someone please help me out w/ this ASAP...thanks much
 

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

1. What is C++?

C++ is a high-level programming language that is widely used for developing software applications. It was developed in the 1980s as an extension of the C programming language. C++ is known for its efficiency, performance, and ability to create complex programs.

2. What are the benefits of using C++ for a project?

C++ offers a wide range of benefits for programming projects. It is a versatile language that can be used for various applications, including system software, game development, and web development. It also allows for low-level memory manipulation, making it suitable for resource-constrained systems. C++ is also highly portable and has a large community, making it easy to find support and resources.

3. What are the key features of C++?

C++ is an object-oriented language, meaning it allows for the creation of classes and objects to organize code. It also has features such as inheritance, polymorphism, and encapsulation. C++ also supports multiple programming paradigms, including procedural, functional, and generic programming. Additionally, it has a rich standard library that provides a wide range of functions for various tasks.

4. What are the common challenges when programming in C++?

One of the main challenges of programming in C++ is its complexity. It has a steep learning curve and requires a good understanding of programming concepts such as memory management and pointers. C++ can also be prone to errors such as memory leaks and segmentation faults if not used properly. Additionally, the syntax of C++ can be verbose, making it more time-consuming to write code compared to other languages.

5. How can I improve my skills in programming C++?

To improve your skills in programming C++, practice is key. Start by learning the fundamentals of the language and then move on to more advanced topics. It is also beneficial to read code written by experienced developers and to participate in online communities to learn from others. Additionally, try to work on personal projects and challenges to apply your knowledge and improve your problem-solving skills.

Similar threads

  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
14
Views
2K
  • Programming and Computer Science
Replies
8
Views
885
  • Engineering and Comp Sci Homework Help
Replies
15
Views
2K
  • Programming and Computer Science
Replies
11
Views
1K
Replies
40
Views
2K
  • Programming and Computer Science
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
15
Views
1K
  • Programming and Computer Science
Replies
5
Views
860
  • Engineering and Comp Sci Homework Help
Replies
2
Views
836
Back
Top