NathanOliver 429 Veteran Poster Featured Poster

I have to go with MSVC++ 2010. I really love the debugger and if you mistype a variable name it will get a red underline letting you know it doesn't know what it is.

NathanOliver 429 Veteran Poster Featured Poster

The modulo operator is the remainder operator. it says what is left after I divide x by y. So if you do 10 % 2 you get zero because 10 / 2 = 5 with nothing remaining. If you do 10 % 4 you get 2 because 10 / 4 = 2 so 4 goes into 10 two times and there will be 2 remaining. The way to calculate % is

let x = number to get the mod from
let y = number to mod against

mod = x - ((x / y) * y)

2 = 10 - ((10 / 4) * 4)

2 = 10 - (2 * 4)

2 = 10 - 8

2 = 2
this calculation only works when doing integer division
NathanOliver 429 Veteran Poster Featured Poster

First void main() is not standard. Main should always return an int. Secondly if you want to use things from the standard library then you will either need to use a using directive or fully qualify the names.

#include <string>

int main()
{
    string word;  // error compiler does not know what string is
}
#include <string>

using std::string

int main()
{
    string word;  // okay, compiler knows where string is
}
#include <string>

using namespace std;

int main()
{
    string word;  // okay, compiler knows where string is
}

The third snippet of code is not as preferred as the second snippet because including the entire std namespace is not necessary and can cause name conflicts. My rule of thumb is never include anything you don't need.

Another issue with your code is that you are including a bunch of headers but you are not using most of them. I did not see the <string> header in your project.

Lastly why are you using printf() ? If your are programing in c++ use cout and cin. That should get you going.

NathanOliver 429 Veteran Poster Featured Poster

line 52 should be Stack g; . The reason for this is the compiler is interpreting line 52 as a function that returns a Stack and takes no arguments.

NathanOliver 429 Veteran Poster Featured Poster

No you are not correct. The function on line 19 is used to compare to box objects.

coolbeanbob commented: I like this guy +3
NathanOliver 429 Veteran Poster Featured Poster

Use a char array and a for loop. Store the input into the array and loop through it to find the largest number.

WaltP commented: The first post that makes any sense at all!!! +17
NathanOliver 429 Veteran Poster Featured Poster

The problem with your algo is that when you get to numbers like 15 which are divisible by both 3 and 5 you add it in twice. I think a a better way would be to use one for loop from 3 to 1000 and check with an if statement if the number is divisible by either 3 or 5. If it is add it to the total if not continue. One way you can make it run a faster is to skip all even numbers. (hint) You can do this in the step condition in the for loop.

Grovega commented: Thank you :) +0
NathanOliver 429 Veteran Poster Featured Poster

In between lines 5 and 6 try adding

timestamp.erase(timestamp.end() - 1);
iamthesgt commented: Thanks man! +2
NathanOliver 429 Veteran Poster Featured Poster

When you declare an array or a vector you don't subtract one from the size when you declare it.

int foo[30];  // creates a array of size 30 indexed from 0-29
vector<int> bar(30);  // creates a vector of size 30 indexed from 0-29

if you do

int foo[29];  // creates a array of size 29 indexed from 0-28
vector<int> bar(29);  // creates a vector of size 29 indexed from 0-28

@Ancient Dragon 0,1,2...29,30 counted up is 31

Ancient Dragon commented: good catch :) +17
NathanOliver 429 Veteran Poster Featured Poster

on lines 64 through 67 you are passing the drivers address to the functions but you defined the functions as taking a driver by value. Here is the different ways you can pass an argument to a function.

#include <iostream>

using namespace std;

int PassByValue(int value)
{
    return value += 5;
}

int PassByReference(int & value)  // & is used here to signify a reference
{
    return value += 5;
}

int PassByPointer(int * value)
{
    return *value += 5;
}

int main()
{
    int value = 5, returner;
    cout << value << endl;
    returner = PassByValue(value)
    cout << After PassByValue() value is: " << value << "\treturner is: " << returner << endl;
    returner = PassByReference(value);
    cout << After PassByReference() value is: " << value << "\treturner is: " << returner << endl;
    returner = PassByPointer(&value); // & is used here to pass an address
    cout << After PassByPointer() value is: " << value << "\treturner is: " << returner << endl;
    return 0;
}
NathanOliver 429 Veteran Poster Featured Poster

IF you want quit to work right you need to add return 0; after line 91 in your else if block.

else if (playerCreateChoiceOrNot == 5)
{
    quit();
    return 0;
}
Keichemon commented: Thanks for your help. +0
NathanOliver 429 Veteran Poster Featured Poster

IF you want to have 3 colums with 10 rows each then you are going to need 2 loops. One loop controls what row you are on and the other loop will control what colomn you are in. Look at this loop

string foo[41]
for (int i = 0; i < rows; i++)
{
    cout << foo[i];
}

This loop would only print out just the rows. So now we have to put another loop inside the row loop to print the seperate colums.

for (int i = 0; i < rows; i++)
{
    for (int j = 0; j < cols; j++)
    {
        cout << foo[...]
    }
}

I left then index blank for you to figure out. If you go through it step by step you should figure out how to use i and j to get the right value. Look at what index starts each row. In this case it would be 0,3,6,9,12... and the ending index of each row is 2,5,8,11,14...

NathanOliver 429 Veteran Poster Featured Poster

so you want the system call to say "Net User name"? If that's all then you can use a string and put the two parts together and then pass the whole thing to system.

string command = "Net User ";
string name;
cout << "please enter the user name: ";
cin >> name;
commmand += name;
system(command.c_str());
NathanOliver 429 Veteran Poster Featured Poster

the problem is you are using uninitialized variables to do your computations. in case 2 you are using yearsWorking without ever storing a number in there.

NathanOliver 429 Veteran Poster Featured Poster

Why are you even declaring aonther DAI? If you want to youse the getCountry function all you have to do is

for(int i=0; i < answer; i++)
{
    A.push_back(DAI());
    A[i].getCountry();
}
NathanOliver 429 Veteran Poster Featured Poster

in your .cpp file you will need to include the .h file that the defenition is in. than you define the functions like you would a normal function but you have to add the class name to the front of the function name. note that if you are using templates you have to define the functions in the .h file

#include "class.h"

void ClassName::Function(int foobar)
NathanOliver 429 Veteran Poster Featured Poster

Check this out.

NathanOliver 429 Veteran Poster Featured Poster

Another use for pointers is for passing to functions. When you pass a pointer to a function anything you do to it inside your function is retained in the calling function

void foo(int a)
{
    a += 5;
}

void bar(int * a)
{
    *a += 5;
}

int main()
{
    int a = 3;
    std::cout << "a is: " << a << std::endl;  // will be 3
    foo(a);
    std::cout << "after foo() a is: " << a << std::endl;  // will be 3
    bar(&a);
    std::cout << "after bar() a is: " << a; // will be 8
    return 0;
}
NathanOliver 429 Veteran Poster Featured Poster

use the pow function.

foo = pow(bar, 3);
kra9853 commented: humorous and helpful +1
NathanOliver 429 Veteran Poster Featured Poster

on lines 15 and 17 you are setting your counter variable to -1. when it tries to access element -1 it throws an error. try setting the variables to 0 and see what happens.

NathanOliver 429 Veteran Poster Featured Poster

I would like to add that you should not be using void main. per the c++ standard main should always return a int.

NathanOliver 429 Veteran Poster Featured Poster

He is using global variables bradonrunyon.

NathanOliver 429 Veteran Poster Featured Poster

if you want to store the address of that element in you vector than you can do

vector<int*> stack
stack.push_back(&(array[1][1]))

if you are trying to store the value of x and y values you can use a 2d vector like

vector< vector<int> > stack
vector<int> temp;
if (array[x][y] == something)
{
    temp.push_back(x);
    temp.push_back(y);
    stack.push_back(temp);
    temp.clear();
}

although this might not be the best way to do it.

aravind rao commented: Great helpful post +0
NathanOliver 429 Veteran Poster Featured Poster

Are you sure that ContactPtr is holding a BCorp and that it is getting cast right? Also why are you casting objects to a double * in you contact object.

NathanOliver 429 Veteran Poster Featured Poster

you can always use the next_permutation function located in <algorithm>. As mike said you will need to break up then number into each digit and put them into some kind of container. Vectors work well for this. then you will need to sort the container to have the smallest digit at the front of the array. Then you can use a counter variable and a while statement to add up all of the permutations you can get.

int counter = 0;
vector<int> container; // put each digit here
// sort the vector
while(next_permutation(container.begin(), container.end())
{
    counter++;
}
// now counter has the number of permutations
NathanOliver 429 Veteran Poster Featured Poster

What it is doing is testing if you broke the loop or ran to the end. If you ran to the end of the loop than if (j > (i / j)) will be true. If you broke the for loop because if (!(i % j)) returned true than if (j > (i / j)) will be false and the nymber is not prime.

NathanOliver 429 Veteran Poster Featured Poster

I think the problem is coming from the way you are using your if...else statements. On line 54 you check to see if the area is greater than 750 and if it is you add your base_cost with 750 and store it into total_cost but if its not you don't add the base_cost. Try walking through your code with your debugger and see if its doing what you think it should be doing.

NathanOliver 429 Veteran Poster Featured Poster

First void main is a big no no. main should return an int and only an int. Second <iostream.h> is depreciated and should not be used as well. You should use <iostream> . Lastly please use indentation in you code. It makes it much easier to read.

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

You can use string streams to convert a string into a number. this is from dave's new wiki

NathanOliver 429 Veteran Poster Featured Poster

I take it that it works that way because it is a stream and all we are doing with string stream conversions in outputting to the stream and then inputting it back into a variable? Thanks for the approval. Its always nice to have someone like what I have written.

NathanOliver 429 Veteran Poster Featured Poster

No problem glad to help.

NathanOliver 429 Veteran Poster Featured Poster

instead of what you have on lines 118 through 126 try doing this

int counter = 1;
for (int i = 1, j = 0; i < numberUsed; i++)
{
    if (entry[i] == entry[i - 1])
        counter++;
    else
    {
        store[j] = entry[i - 1];
        count[j] = counter;
        counter = 1;
        j++;
    }
}
Griff0527 commented: Provided an excellent example that still required me to correct my own errors +1
NathanOliver 429 Veteran Poster Featured Poster

Making a 2d array for this is pretty strait forward. Because you don't know how many duplicates are in the array you would need to have an array like

int ** twoDarray = new int*[size];
for (i = 0; i < size; i++)
    towDarray[i] = new int[1];

Now all you have to do is loop through the array with a for loop that has two separate counter. One will be for the one D array and the other will be for the 2d array. Something like this

int counter = 0;
for (int i = 0, j = 0; i < size; i++)
{
    //...
}

As you are going through the loop test to see if the element at oneD is the same as the previous element and if it is increment counter. If it is not than then store the counter into twoDarray[j][0], then reset counter to 0 and then increment j. This isn't very elegant but it should get the job done.

NathanOliver 429 Veteran Poster Featured Poster

Well the main problem with starting the construction of a class from the derived part up to the base is that any variables you are using that are in your base in a function in your derived class would be undefined. Assume this situation.

class A
{
    int number;
};

class B : public A
{
    void foo() { number++; }
};

In this situation the compiler would have no idea what number is when it tried to compile it if it were to start at B and go to A. Since it goes the other way there is no problem.

NathanOliver 429 Veteran Poster Featured Poster

I'm not exactly sure what you mean by adding or multiplying a file. Also what do mean by reducing the file by a few bytes. A AMD 2 GHZ processor single core will do about 3500 MIPS or 3500000000 instructions per second. A 2 GHZ processor will have 2 billion CPS so if you instruction needs 10 cycles to complete you could do it 200,000,000 times in one second. As for what is an instruction its basically anything you tell the processor to do and instructions have different CPI depending on how complex they are.

Ancient Dragon commented: nice answer +28
NathanOliver 429 Veteran Poster Featured Poster

Yes it is unnecessary. Didn't really think about it I just wrote what first came to mind. Thanks for pointing that out invisal. It could easily be written this way and it is probably faster.

void computeCoin(int coinValue, int& number, int& amountLeft)
{
    number += amountLeft / coinValue;
    amountLeft = amountLeft % coinValue;

}
NathanOliver 429 Veteran Poster Featured Poster

I think the hint might be for the the change function and not for the user input loop. the change function you wrote could be rewritten like this

void computeCoin(int coinValue, int& number, int& amountLeft)
{
    if (amountLeft % coinValue == 0)
    {
        number += amountLeft / coinValue;
        amountLeft = 0;
    }
    else
    {
        number += amountLeft / coinValue;
        amountLeft = amountLeft % coinValue;
    }
}
NathanOliver 429 Veteran Poster Featured Poster

do you want to have two separate add methods in you derived class? one that takes an int and one that takes a void pointer?

NathanOliver 429 Veteran Poster Featured Poster

Just start off with a blank vector and push the objects on.

class Foo
{
    // ...
}

int main()
{
    vector<Foo> container;
    for (int i = 0; i < 10; i++)
    {
        container.push_back(Foo());
    }
}
fandango commented: Thanks for the code example as well. +0
NathanOliver 429 Veteran Poster Featured Poster

Thank you AD for your reply. The single slash in my code was a typo. As for having a ? act as a any single letter I am implementing that right now and I should have it finished shortly. I'll post the updated code once its done.

@ Excizted I fixed what was causing the problem and when I post the updated code "*.php" for searchFor and "MyScript.php" for word will work.

NathanOliver 429 Veteran Poster Featured Poster

Hey All

This code is for matching a string with a wildcard in it to another string. If you want to have a Astrix in the first string be counted as a character and not as a wildcard put a \ in front of it. I have tested it for quite a few different possibilities and it has worked for what I have tested it with. Include is a short main function demonstrating it working. Fell free to use it if you want but I CAN'T guarantee that it is bug free.

Nathan

Ancient Dragon commented: Good job :) +28
Zoon commented: Very useful :) +1
NathanOliver 429 Veteran Poster Featured Poster

First void main is not standard. main should only return an int as per the ISO standard. Secondly all of your header files are deprecated. What compiler are you using? You might also want to change where you compare the user answer to the answer in the file. I would do it right after the user enters in there answer so they know right there if they got it wrong or not.

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

I do agreee that vectors do have advantages but this is still c++. It is still usefull to know how to do these things because there are times when you would be better of with a 2d array instead of a 2d vector.

NathanOliver 429 Veteran Poster Featured Poster

here you go solution

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

is the unlink function in the library part of a namespace?

NathanOliver 429 Veteran Poster Featured Poster

Can you get rid of the unlink function in you class?

NathanOliver 429 Veteran Poster Featured Poster

That's just it I don't know. Is this your code? If not where did it come from. To me it seems to be a macro someone created to assist in debugging.

NathanOliver 429 Veteran Poster Featured Poster

the problem is with your set1st function. you need to set the member variables to the inputted variables. Also it should be a void function.

void set1st(int x1, int y1, char z1)
        {
            x = x1;
            y = y1;
            z = z1;
            setBoard();
            board[y][x] = z;
            displayBoard();
        }

Then in your move function you don't need to pass the variables to it just use the member variables.

void moveup()
{
     if (y < 2)
     {
         set1st(x, y, 'X');
         return;
     }
     set1st(x, y - 1, 'X');
}

Also you should move the system("CLS"); to right after getch(t); in your move function. This should get you on your way.

NathanOliver 429 Veteran Poster Featured Poster

Here is a general purpose set up that should work for you.

int rows, cols;
// get rows and cols from user
int ** array2d;
array2d = new int*[rows];
for (int i = 0; i < rows; i++)
    array2d[i] = new int[cols];
NathanOliver 429 Veteran Poster Featured Poster

part of the problem you are having with your multiplication is you are setting carry to 1 if the result is greater than 9 but that isn't right. 7 * 7 is 49 so your carry should be 4 in this case and not 1 as you have it.