NathanOliver 429 Veteran Poster Featured Poster

all of your function definitions do not name the variables that you are passing to them. You are also declaring the variables that you are passing to your functions globally. You don't need to have any function parameters if you are only using global variables but I suspect that your are supposed to be declaring the variables in main and then passing them to your functions. there also seems to be some accessing of array elements that are out of bounds but its hard to tell without any indention in your code.

NathanOliver 429 Veteran Poster Featured Poster

what happens if you change line 32 to

double root = sqrt(double(number)) + 1;

[EDIT]
I think you might also want to recheck the way you are incrementing your test variable.

NathanOliver 429 Veteran Poster Featured Poster

if you want to take data in as a string and convert it you can do:

// you have to have these
#include <strstream>
#include <string>
int number;
std::string input;
std::stringstream ss;
cout << "enter number: ";
getline(cin, input);
ss << input;
ss >> number;  // now number is filled with the number from input;

Here is a handy little function I wrote that works like this

template <typename T>
void StringToNumber(std::string number, T & output)
{
    std::stringstream ss;
    ss << number;
    ss >> output;
}
NathanOliver 429 Veteran Poster Featured Poster

what you need to do is take the integer supplied to the function and figure out what day of the week it should be. lets say i passed 13 to the function and the current day is Tuesday. i would mod 13 by 7 and get 6. so now i have to find out if 6 plus the index of Tuesday is past the end of the array. Tuesday is in index 2 and 6 + 2 is 8 which is past the end of the array. so now we subtract 7 from 8 and get 1. at index 1 in are array we get Monday. that is how you do it. i cant really give you the code for it since this is what you are supposed to be doing.

NathanOliver 429 Veteran Poster Featured Poster

i would use a char array for your input but rather a string

string input;
set<string> dictionary;
// open file
while(getline(nameFile, input)) // read untill there is nothing left to read
{
    set.insert(input); // insert into set
}
// print contents
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

What are the errors you are getting? Also your addDay function is not right. it should accept an integer parameter and add that to the current day to get the new day.

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

Why are you defining your functions inside main?

NathanOliver 429 Veteran Poster Featured Poster

if you have a vector of floats you might want to use the for_each function in the algorithms header.

NathanOliver 429 Veteran Poster Featured Poster

are you coding for C++ or C

NathanOliver 429 Veteran Poster Featured Poster

Well if you have to use char arrays than you can just make the array large enough to handle most inputs or you can write a function to change the size of the array during run time.

NathanOliver 429 Veteran Poster Featured Poster

Well if you need dynamic c-string arrays I would suggest using string from the STL. as far as an a array of structures thats pretty simole too. you can use a hard coded array or you can use one of the containers avalible in the STL. In this case a would use a vector.

struct Speaker
{
    string name;  // use string here for any size string
    string topic;
    string telNumber;
    double fee;
}

Then you can have a vector of Speakers that will hold each speaker that you have. With that vector you can add to it search through it and get the size.

vector<Speaker> Speakers;  // create the vector that holds Speakers
Speaker temp;  // make a speaker
Speakers.push_back(temp);  // this adds the speaker to the back of the vector.
NathanOliver 429 Veteran Poster Featured Poster

you have your code like this

int firstNo;// first number is stored here
int secondNo,
int resultAdd,// variable for result when first number and second number are added
int resultSub,// variable for result when first number and second number are subtracted
int resultMult,// variable for result when first number and second number are multiplied
int resultDivi// variable for the reult when the first number and second number are divided

// when it should like this
int firstNo;// first number is stored here
int secondNo;
int resultAdd;// variable for result when first number and second number are added
int resultSub;// variable for result when first number and second number are subtracted
int resultMult;// variable for result when first number and second number are multiplied
int resultDivi;// variable for the reult when the first number and second number are divided

// or like this

int firstNo, secondNo, resultAdd, resultSub, resultMult, resultDivi;
NathanOliver 429 Veteran Poster Featured Poster

What compiler are you using? also the way to define the standard headers is to not include a .h after it.

#include <iostream>
#include <ctime>
#include <string>
#include <vector>
//...
NathanOliver 429 Veteran Poster Featured Poster
NathanOliver 429 Veteran Poster Featured Poster

well if you want to convert a char to an int you have to do this

char temp = '2';
int number = temp - '0';  // number is now 2
// if you do this
int number = temp;  // number is now 50
NathanOliver 429 Veteran Poster Featured Poster

Does this program run correctly? Lines 57-75 looks like it is an infinite loop. On lines 97 and 98 you have 2 return statements. You can only return one thing from a function. This is not to say you cant have a multiple returns in a function, you just cant have it like you have it.

int foo()
{
    int bar = 5;
    int temp = 6;
    return bar;
    return temp;  // this is incorrect.
}

int foo()
{
    int bar = 5;
    int temp = 8;
    if (bar > temp)
        return temp;
    return bar; // this is fine since the first return is in a conditional
}
NathanOliver 429 Veteran Poster Featured Poster

Do you really need to use strcmp? String's have a built in operator == that you can use for comparison.

std::string foo = "foo";
std::string bar = "bar";
if (foo == bar)
    std::cout << "foo and bar are equal.";
else
    std::cout << "foo and bar are not equal.":

^^^ firstPerson beat me to it ^^^

NathanOliver 429 Veteran Poster Featured Poster

here is a good link to how next_permutation works. http://marknelson.us/2002/03/01/next-permutation

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

@ Nandu Das The purpose of this forum is to help not to just give you the code. If you are having a particular problem with this problem then state what that is and we can help. With that said you can do this very simply. you will need three variables and a while loop. I would use min, max and input and I would set them all to 0. Ask the user to enter a number and store that number into min and max. Then in a while loop that loops forever ask the user to enter a number or something like -999 to quit. use cin >> input; to get the number entered by the user. Then compare input to -999. If it is equal then break the loop. if not then see if the number is less than min. if it is then set min = input. Then check to see if input is greater than max. If it is than set max = input.

NathanOliver 429 Veteran Poster Featured Poster

Well I am having some problems getting it to link with the SFML but I wasn't able to get your error. I changed your include to #include <c:\Users\Samuli\Documents\Visual Studio 2008\Projects\RPG\RPG\player.h> . That might help you.

NathanOliver 429 Veteran Poster Featured Poster

Would you feel comfortable attaching all of your code so I can try and compile it on my machine? I would also need the SFML/Graphics.hpp and SFML/Network.hpp or a link to get the library.

NathanOliver 429 Veteran Poster Featured Poster

The only thing I can think of is that the include path is not right.

NathanOliver 429 Veteran Poster Featured Poster

It looks like you include for player.h inn your server playerHandaler is wrong. Why are you using / for the directory switches? Shouldn't it be a \?

NathanOliver 429 Veteran Poster Featured Poster

Can you post you playerHandaler code?

NathanOliver 429 Veteran Poster Featured Poster

You added it to player.h or player.cpp?

NathanOliver 429 Veteran Poster Featured Poster

Do you have #include <string>? I don't see it in player.h

NathanOliver 429 Veteran Poster Featured Poster

In your build log it shows its compiling 2 playerhandeler.cpp and 2 main.cpp. maybe something going on there.

NathanOliver 429 Veteran Poster Featured Poster

Why are you using c functions in c++ code? Also you are mixing strings and char arrays. Is there a reason for that? Lastly you should not use eof() for you while loop. Just use your getline staement for your while condition.

NathanOliver 429 Veteran Poster Featured Poster

No its not in the debug sub directory or no you are not looking there?

NathanOliver 429 Veteran Poster Featured Poster

Do you have a tree already or do you need one? Also what type of data does the file have? What I mean by that is, is child1 a string or something else you are just calling it child1?

NathanOliver 429 Veteran Poster Featured Poster

The reason you had an error saying "missing ; before using" is because you were missing the ; in you other file and so it was telling you that somewhere before using you should have a ;. Try taking it out of your code now and see if it complains.

NathanOliver 429 Veteran Poster Featured Poster

How is your matrix defined? If it is a class than you can put it into a std::list . Also you can add a get funtion to your class that will return the element you are looking for.

class Matrix
{
    //...
    int GetData(int row, int col); // returns the value at [row][col]
    //...
};

// in main
Matrix temp(3,3); // assuming you have a constructor like this
std::list<Matrix> matrices;
matrices.push_back(temp);
NathanOliver 429 Veteran Poster Featured Poster

The reason this is happening is there is a newline left in the buffer from line 145. when you call getline() in you accessUNIT() function it reads in the newline and that's all. To fix it put cin.get(); on line 146. Try reading this for more information.

NathanOliver 429 Veteran Poster Featured Poster

What exactly is the LNK2019 error saying?

NathanOliver 429 Veteran Poster Featured Poster

I looked at the book and it looks like since there are multiple keys that are the same the author decided to have each rule be in a vector. That way you have one key "adjective" and then a vector that has 3 different rules in it. This way one key can have multiple sets of rules associated with it.

NathanOliver 429 Veteran Poster Featured Poster

I would suggest using an implementation like Nichito purposed.

bool valid = true;
do
{
    cout << "Enter a social security number without dashes: ";
    getline(cin, socialNum);
    size_t size = socialNum.size(), counter = 0;
    while(counter < size)
    {
        if(...)
        {...}
        else
        {
            valid = false;
            cout << "Invalid input!\n";
            break;
        }
    }
} while (!valid);
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

No problem. Glad to help.

NathanOliver 429 Veteran Poster Featured Poster

Yes the minimum is 4 but what do you get for output if you run this

#include <iostream>
using namespace std;


int main()
{
    cout << sizeof(long int);
    cin.get();
    return 0;
}

I got 4 for my output.

NathanOliver 429 Veteran Poster Featured Poster

@ stuXYZ According to my MSDN a long int and a int are the same thing? are the different with the compiler you are using? I re wrote the for loop this way to make it work with size_t and not have to use an offset.

for (size_t i = input.size() - 1; i != -1; i--)
NathanOliver 429 Veteran Poster Featured Poster

Well I looked at some other code I have written and I used std::string::npos in it so I guess MSVC++ 2005 will take it either way.

NathanOliver 429 Veteran Poster Featured Poster

Sorry I found what it was. Since we are going backwards I forgot size_t wont work. If you change the for loop to this it should work.

for (int i = input.size() - 1; i >= 0; i--)
NathanOliver 429 Veteran Poster Featured Poster

What error are you getting? I am using MSVC++ 2005

NathanOliver 429 Veteran Poster Featured Poster

Lines 21 and 22 are wrong. They should be

hasSetPages = new bool;
hasSetColor = new bool;
NathanOliver 429 Veteran Poster Featured Poster

That could be a possibility. You would have to run them side by side to see if there is a difference.

NathanOliver 429 Veteran Poster Featured Poster

What exactly do you want to do if there is a non number in the string? that will determine what you need to do.

NathanOliver 429 Veteran Poster Featured Poster

@ Dave Not sure why you are getting a compiler error. It runs fine on my machine. Just in case there is a typo this the the exact code that I created that does work.

#include <iostream>
#include <string>

int main()
{
    size_t firstPos = 0, secondPos;
    std::string temp = "4ab030 <__do_global_ctors_aux>";
    std::string sub;
    if ((firstPos = temp.find_first_of("<", firstPos)) != std::string.npos)
        if ((secondPos = temp.find_first_of(">", firstPos + 1)) != std::string.npos)
            sub = temp.substr(firstPos, (secondPos - firstPos + 1));
    std::cout << sub;
    std::cin.get();
    return 0;
}

@ dansnyderECE I wasn't sure if the tags could be anywhere so I came up with this. Since there only at the end your solution works just fine.