NathanOliver 429 Veteran Poster Featured Poster

please re-post this code with code tags and proper indentation.

NathanOliver 429 Veteran Poster Featured Poster

well you need to move your bid class above your simulator class to fix the second error because you are trying to use it before you have defined it. for the first error try using

list.push_back ( this->getBids() );
NathanOliver 429 Veteran Poster Featured Poster

to delete a pointer and know that it will never be a problem do

Foo* p = new Foo;
// later on
delete p;
p = 0;
// since p is zero calling delete again will be safe
NathanOliver 429 Veteran Poster Featured Poster

You have i and j initialized to size so you are actually pointing to one passed the end of the vector. Replace

int i=(int)ask.size();
     int j=(int)buy.size();

with

int i=(int)ask.size() - 1;
     int j=(int)buy.size() - 1;

Also with this line

matchedAsk.insert(matchedAsk.end(),ask.end(), ask.end()+1);

I belive you are using the iterators to insert the element of the vector into another container. But end() poins to one past the end of the vector so if you want to get the last element in the vector you would have to use

matchedAsk.insert(matchedAsk.end() - 1,ask.end() - 1, ask.end());
NathanOliver 429 Veteran Poster Featured Poster

Thanks for your replies abhimanipal. I'll leave this post unsolved for now in case anyone else would like to chime in. Thanks guys.

NathanOliver 429 Veteran Poster Featured Poster

Thanks Dani

NathanOliver 429 Veteran Poster Featured Poster

Sounds like you might need to re flash your bios.

NathanOliver 429 Veteran Poster Featured Poster

Looks like it is fixed now.

NathanOliver 429 Veteran Poster Featured Poster

Well I'm glad it isn't just me. Thought I was going more insane than I already am.

NathanOliver 429 Veteran Poster Featured Poster

The reason I was using a for loop was to reduce the number of function calls. If it is not that much of an overhead then I would gladly change my code to not have a for loop.

NathanOliver 429 Veteran Poster Featured Poster
void primeFactors(int num,vector<int>& v1,int start)
{
     int i=0;
     
     if(num<=1)
           return ;
     else
     {
            if(num%start==0)
            {
                v1.push_back(start);
                primeFactors(num / start, v1, start)
            } 
            else
            {
              primeFactors(num, v1, start++)
            }
     }
}

i believe this is what you are hinting at correct?

NathanOliver 429 Veteran Poster Featured Poster

There is also a problem with the page buttons. Trying to hit next or 2,3,4... goes to the associated page in the administrator forum. At least for me that is.

NathanOliver 429 Veteran Poster Featured Poster

Same thing in troubleshooting dead machines

NathanOliver 429 Veteran Poster Featured Poster

I did that about 30 minutes ago after it popped into my head but thanks Vernon for pointing that out.

NathanOliver 429 Veteran Poster Featured Poster

I have to agree that the post are to wide now. I have to shrink my browser in order to get a window where I don't have to turn my head to see the whole line. BTW my res is 1280 x 1024 on a 19" monitor

NathanOliver 429 Veteran Poster Featured Poster

I admit the returns do look wired but when I get rid of them the program does not work right. Also by using the /= or -= operator causes problems as well. I guess my logic is so messed up that doing it the right way makes it worse :). Maybe we could call this a hybrid function? well thanks guys for the responses I think I'm going to rest on it and try something different tomorrow.

NathanOliver 429 Veteran Poster Featured Poster

Hey All

Yesterday I was writing a recursive form of a prime factorization program and I wasn't sure about the syntax I used. the function works as is but I'm curious if I am being redundant or if this is the proper way to code it.

Here is what I came up with

void PrimeFactorize(unsigned int number, vector<unsigned int> & factors)
{
	if (number == 1)
		return;
	if (number % 2 == 0)
	{
		factors.push_back(2);
		return PrimeFactorize(number / 2, factors); // not sure about this
	}
	else
	{
		for (unsigned int i = 3; i <= number; i += 2)
		{
			if (number % i == 0)
			{
				factors.push_back(i);
				return PrimeFactorize(number / i, factors);  // here too
			}
		}
	}
	return;
}

The syntax I am talking about is on lines 8 and 17. I didn't know if I should put the return in or just call the function.

NathanOliver 429 Veteran Poster Featured Poster

could you post the code you so far?

NathanOliver 429 Veteran Poster Featured Poster

well i looked on my MSDN and from what i found there is a System.Drawing namespace. Could this be what it should be?

using namespace System.Drawing;
NathanOliver 429 Veteran Poster Featured Poster

on line 6 you are doing subtraction not addition. is that a typo or is this happening in you subtraction function?

NathanOliver 429 Veteran Poster Featured Poster

could you please post the point class code.

NathanOliver 429 Veteran Poster Featured Poster

I am sad that he will not be with us anymore. He had given me some wonderful advice and wasn't afraid to call me out if what I said was incorrect. He will be missed

NathanOliver 429 Veteran Poster Featured Poster

personally I'm not a big fan. I don't like all of the empty space at the bottom of a post. It makes it take up to much space. Just when I get used to the old interface they change it on me again. BTW is there a post that explains what the new symbols mean?

NathanOliver 429 Veteran Poster Featured Poster

well I'm not seeing a getName() function that returns an int so I'm clueless.

NathanOliver 429 Veteran Poster Featured Poster

is Color part of using namespace System::Drawing; ? if not you need to include it in your point class. this is all i can get from this.

NathanOliver 429 Veteran Poster Featured Poster

this is because of line 17. you are setting a pointer equal to another pointer so whatever happens to temp will also happen to b. if you want only the data in b to be the same as temp but not actually point to the same object you would have to do something like

node* temp = new node;
node* b = new node;

temp->data = "hello";
b->data = temp->data;
NathanOliver 429 Veteran Poster Featured Poster

I would look up prime factorization. That should point you in the right direction.

NathanOliver 429 Veteran Poster Featured Poster

Thanks Nick I did not know a vector could be inialized that way..

NathanOliver 429 Veteran Poster Featured Poster

I hard coded them just to show that you can use a vector as well. It was just an example.

NathanOliver 429 Veteran Poster Featured Poster

What would you have done differently? I am open to any and all suggestions.

NathanOliver 429 Veteran Poster Featured Poster

Hey all

I have seen a lot of stuff about palindrome checkers so I thought I would write one that works for STL containers as well as arrays. it accepts a bidirectional iterator to the first element and an bidirectional iterator to 1 after the last element. Included is a sample of it working with a string and a vector of int's. At most this function requires O N/2 iterations(correct me please if I'm wrong). Also I chose for single characters to be considered a palindrome. I hope you guys will find this useful.

NathanOliver 429 Veteran Poster Featured Poster

i think that is because you commented out you bible constructor. also in main you are doing bib.setInput; when it should be something like

string foo;
Bible bib;
bib.setInput(foo);
return 0;
NathanOliver 429 Veteran Poster Featured Poster

i would just comment it out then by using the // in front of the definition and the decleration.

class Bible
{
public:
//Constructors
Bible();
//Bible(string nam, int chapt, int vers, string testa, string txt); here

//Mutators
//Bible::Bible(string nam, int chapt, int vers, string testa, string txt) //Initialize to any size   and here
// dont put any braces yet since you are not using it yet.
NathanOliver 429 Veteran Poster Featured Poster

could you post your new code?

NathanOliver 429 Veteran Poster Featured Poster

there are a bunch of post already about doing this.

try this http://www.daniweb.com/forums/search6116243.html

NathanOliver 429 Veteran Poster Featured Poster

the problem is line 18.

Bible::Bible(string nam, int chapt, int vers, string testa, string txt)

you dont have anything defined for this function. it should be

Bible::Bible(string nam, int chapt, int vers, string testa, string txt) 
{
       // stuff here
}
NathanOliver 429 Veteran Poster Featured Poster

the function is constantly reducing the number untill it is less than 10.
lets say the number is 100. the function would print 0 for the first time. then you check to see if it is greater than 10. since 100 is greater than 10 we will call the print function but this time we will dived 100 by 10 and pass that into the function.

so now we have 10. we do the same thing and again it displays 0. 10 is not less than 10 so we dived 10 by 10 and call the function again.

now we have 1. 1 % 10 is 1 so it displays 1. now 1 is less than 10 so we print out a blank line and exit the function via the return statement. since this is a void function we don't need to return anything.

So this function prints out a number backwards using recursion. if you still are unclear about any of this let me know. also if you are using a newer compiler i would suggest setting a break point in the function and stepping through it with the debugger to watch it work.

[EDIT]
Xorlium beat me to it. ;)

NathanOliver 429 Veteran Poster Featured Poster

I know when I used to have MSVC++ 6.0 it had a special installer to install a bunch of old school NT dll's. maybe they stooped doing that so those errors come up.

NathanOliver 429 Veteran Poster Featured Poster

I'm feeling helpful so I'll show you one way to do this.

int counter = 1, x,y, zeroX, zeroY;
int map[10][10];
srand((unsigned)time(0));
zeroX = rand() % 10;	// this gets the spot to put the zero
zeroY = rand() % 10;
// place zero
map[zeroX][zeroY] = 0;
while (counter < 100)
{
	x = rand() % 10;
	y = rand() % 10;
	if (x == zeroX && y == zeroY) // check to see if we are at the zero
		continue;
	else
	{
		map[x][y] = 1;  // if not make it a 1
		counter++;
	}
}
NathanOliver 429 Veteran Poster Featured Poster

well for starters the code you are using to populate the array with your o's and x's is not right. you are using a for loop but what would happen if the cords you get already have a o or an x? you would do nothing and then start the loop from the beginning. this would lead to not having enough o's or x's. i would suggest a while loop with a counter as the condition and you only increment the counter if the if statement executes. i believe the issue you are having with moving the board is that you are not changing the values of x or y so you are doing the same thing every time. also you never reset x or y to something after the last time you use it in your x for loop so x and y are still at the cord.

NathanOliver 429 Veteran Poster Featured Poster

what settings are you using to write this program? what kind of project is it?

NathanOliver 429 Veteran Poster Featured Poster

@ sourabhtripathi *p2--; does not change the memory address. it actually is subtracting 1 from the value stored at p2. also you don't have the values initialized to anything. here is a link for you. http://www.cplusplus.com/doc/tutorial/pointers/

NathanOliver 429 Veteran Poster Featured Poster

Take out the #include "UTevent.cpp" in main

NathanOliver 429 Veteran Poster Featured Poster

Could you post the full error message?

NathanOliver 429 Veteran Poster Featured Poster

as caut_baia stated you are returning a pointer but your function is defined to return just an object
change this

return rslt;

to this

return *rslt;
NathanOliver 429 Veteran Poster Featured Poster

yeah i took a while to write my post and there was a couple of edits. for some reason my fingers don't want to work tonight.

NathanOliver 429 Veteran Poster Featured Poster

it could be that y1 is declared in the <cmath> header and since you declared them as global you are getting the error. what happens if you do this instead instead of having a main.h. I mean put all this in main.cpp

#include <iostream>
#include <cmath>

/* Namescapes */
using namespace std;

int main() {
        /* Varibles */
        double x1;
        double x2;
        double y1;
        double y2;
        double answer;
	/* Title */
	cout << "Fellixombc's Distance Formula Application (Geometry)\n" << "x1: ";
	
	/* Application Input/Output */
	cin >> x1;
	cout << "x2: ";
	cin >> x2;
	cout << "y1: ";
	cin >> y1;
	cout << "y2: ";
	cin >> y2;
	
	/* Calculations */
	answer = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
	
	cout << answer;
	
	system("pause");
	
}

And yes those are common names. you should use real names for your variables.

NathanOliver 429 Veteran Poster Featured Poster

could you please post your code that is giving you this error. it seams like you are re declaring a variable.

NathanOliver 429 Veteran Poster Featured Poster

the reason is that when you declare a variable it is given a memory address and what ever happens to be in that address is what the variable is now equal to. so when you do int i; i has the value of whatever the memory its using has. so to avoid problems you normally want to set them to 0 before you and an manipulations with them.

int i;
i += 100;
cout << i;  // i could be whaterever

// safe approach
int i = 0;
i += 100;
cout << i;  // 100

If you are going to assign to a variable before manipulating it then it is fine to declare it without initializing it.

int i;
i = 100;
i += 1;
cout << i;  // 101

you just don't want to use a variable before you put something in it or as Sodabread said it will have crap in it and nobody wants to have crap.

jonsca commented: Good +4
NathanOliver 429 Veteran Poster Featured Poster

what is the definition of _itms?