- Strength to Increase Rep
- +0
- Strength to Decrease Rep
- -0
- Upvotes Received
- 5
- Posts with Upvotes
- 4
- Upvoting Members
- 5
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
15 Posted Topics
Using a mutex to make things “thread safe” is actually pretty easy. That is what they are designed to do. However, keep in mind, the purpose of a mutex is to protect a Resource, generally some sort of data storage element. You protect Operations (that is sections of executable code) …
A recursive function needs to do several things. 1. It has to test to see if it is done (To see if it has reached a base case). 2. It has to call itself. 3. The data that the function looks at should be different for each iteration, otherwise, it …
One approach would be to read in a line at a time, and then parse the line rather than turning copying characters on and off. You can use some of the string operators to manipulate each line, and then write the resulting line to the output. You still will need …
Try something like: [code] // Create an array, one element per quarter, to hold the index into the records array of // the product with the highest profit. This is compared to the profits of the other // products. int GreatestProfitProd[4]; // Create an array, one element per quarter, to …
I am assuming that you need to keep track of the data as if it is still in a two dimensional array after you read it in. Basically, you have to keep track of three things. You need an index for the one dimensional array, and you need a “row” …
Well, the most obvious bug is that you don’t have a default case for your switch, and you don’t bounds check the user input. Also, you don’t use Pi to calculate the area of the circle. You don’t use Pi to calculate the perimeter, but if you did, the formula …
Al41007 is on the right track, but in his version, on the first pass through the “i” loop (that is when i=0), the “j” loop does not execute. This may be okay. I think it may help to more clearly describe the algorithm. It is actually the sum of (X*(X^n)/n! …
I’m not positive, because I am far from an expert on GCC, but I believe you can (or at least should) only select one optimization level at a time. There are a number of different things that could be done to optimize a program. In GCC, these are controlled by …
I agree that the best way is to put the node where it belongs in the list in the first place. Linked lists should always be ordered in some way. If they are not ordered, then a linked list is the wrong data structure to be using. You should have …
You are getting a message “Debug Assertion fails”, and you are 100% sure that it is from the Sort function. And you are wondering what is wrong with the Sort function. Well, let’s start with the basics. The fact that you get a “Debug” error implies that you are running …
To expand on what Eagletalon said, linker errors are usually not caused by a syntax error in a line of code. They are caused because the linker can’t find something it needs, it finds too many of something, or pieces don’t match. Quick lesson (which you may already know): Linkers …
This would be a good place to use a debug output. Print out the value of power, base, product, and i inside of your "for" loop. This should make it obvious what is going on. Also, you declare "product" in tow different places in your code. You didn't say which …
Okay, I’ll start on my soapbox. I’m not a fan of recursion. It tends to be difficult to add features and enhancements to recursive code without breaking it. Of course, this is not a concern for a student project. Also, recursive code is most applicable to applications that have arbitrary …
In my experience, people from a hardware (i.e., Electrical Engineering) background tend to prefer C over C++, and I suspect this is mostly because they have never had any classes on C++. These are often the same people who are writing embedded software, which is probably where the perception of …
As David said, the strucs are fine. You may want to create a structure to hold the results of your calculations, too. From the problem description, it looks like you have quite a ways to go. I would suggest breaking the problem into a number of pieces: 1. Get input …
The End.
Fortran IV