![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Call me Chuck
|
Multi-dimensional vectors
I'm creating a program to help me solve polynomial multiplication so I won't have to do all that multiplying.(I'm lazy.
)And I have run into a problem. I found that in order for the multiplication to turn out right I have to create dynamic two-dimensional arrays. I messed with new for a bit until I just figured it would be more efficient to just use the vector class. But the problem is I keep on getting "Vector subscript out of range" when I get to a certain point in my program(commented bellow). C++ Syntax (Toggle Plain Text)
Any pointers or help would be highly appreciated! Thanks. |
|
|
|
|
|
#2 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 754
Rep Power: 3
![]() |
Re: Multi-dimensional vectors
The problem is with t in the inner loop. Because it's inside the loop, each time through, you'll reset it to 1, do your work, then increment it. The next time, you set it to 1 (note that j went up by 2), do your work, and increment... repeat as necessary. As it's coded, t will always be 1 when you do the calculations.
__________________
<insert disclaimer here> <insert shameless plug for Visual Studio here> |
|
|
|
|
|
#3 |
|
Call me Chuck
|
Re: Multi-dimensional vectors
I was so distracted by the large computations that I overlooked the little ones!
Thanks.EDIT It fixed that silly little slip-up but I'm still getting the error. EDIT |
|
|
|
|
|
#4 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 754
Rep Power: 3
![]() |
Re: Multi-dimensional vectors
Can you post the new code? or even just the snippet
__________________
<insert disclaimer here> <insert shameless plug for Visual Studio here> |
|
|
|
|
|
#5 |
|
Call me Chuck
|
Re: Multi-dimensional vectors
Exactly the same as the old except that the declaration of t is now out of the loop.
Here: C++ Syntax (Toggle Plain Text)
|
|
|
|
|
|
#6 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 754
Rep Power: 3
![]() |
Re: Multi-dimensional vectors
I ran it again, with 2 binomials. The inner loop condition is true
(num_poly - 1) == 1, so j >= num_poly - 1 will always be true. Then when you're indexing into coeff[j] you end up with an index greater than the size of the vector. Just thinking about it, if you ever had more than 2 binomials, the condition would be false and the loop would never run. You'll have to rework the logic on that one
__________________
<insert disclaimer here> <insert shameless plug for Visual Studio here> |
|
|
|
|
|
#7 |
|
Call me Chuck
|
Re: Multi-dimensional vectors
lol I'm missing a lot lately!
It's been a few months since I last programed, but I didn't expect to be this rusty... off to try it again I guess! |
|
|
|
|
|
#8 |
|
Call me Chuck
|
Re: Multi-dimensional vectors
All my work, foiled.
My friend told me a wrong way to multiply binomials, and now I have to start the initial algorithm from scratch again. Oh well, just more practice right? |
|
|
|
|
|
#9 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 754
Rep Power: 3
![]() |
Re: Multi-dimensional vectors
haha, nice perspective
![]()
__________________
<insert disclaimer here> <insert shameless plug for Visual Studio here> |
|
|
|
|
|
#10 |
|
Call me Chuck
|
Re: Multi-dimensional vectors
Well, I think I figured it out this time, now just a few hours of work... I hope.
![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| reading from file, and vectors question | jasonfrost | C++ | 3 | Oct 3rd, 2007 9:02 AM |
| How do I read .mbm (Multi BitMap) files? | moondog | Other Programming Languages | 19 | Aug 16th, 2007 8:59 PM |
| multi dimensional array error | veiga2 | C++ | 2 | Nov 16th, 2006 3:05 AM |
| Arrays or Vectors? | can342man | C++ | 2 | Apr 20th, 2006 3:57 PM |
| Passing vectors as arguments | Soulstorm | C++ | 6 | Mar 18th, 2006 4:49 PM |