NathanOliver 429 Veteran Poster Featured Poster

Why are lines 15-17 inside your constructor? Your close bracket on line 18 should be on line 15.

phorce commented: Just noticed that! +6
NathanOliver 429 Veteran Poster Featured Poster

Well you could make a base class that has a generic function called getList() that would display the list. Then you could derive your differnt kinds of list from that base class. then the foo() function will get passed a pointer to the base class so it can except both sub list. In the foo() function you would then call the getList of the pointed to object

myk45 commented: thanks! +5
NathanOliver 429 Veteran Poster Featured Poster

You are not reseting count anywhere. After line 16 put count = 0; and see what happenes.

NathanOliver 429 Veteran Poster Featured Poster

I think the issue is comming from how you are sizing the vector. I think you should use this to define the size of the vector in your constructors.

grid.resize(rows);
for (int i = 0; i < rows; i++)
{
    grid[i].resize(cols);
}
NathanOliver 429 Veteran Poster Featured Poster

modify is a char * not a string therefore it does not have rbegin() or rend() member function. Do you have to work with a char * or can you use a string? If you have to use a char * then you need to know the legnth of the string and then you can use a for loop to loop from the back of the string to 0. If you can use a string than you can use a reverse iterator.

NathanOliver 429 Veteran Poster Featured Poster

So what is your problem? From what I can see you dont define count in your strlength function. As far as I can remeber strings from the string type are not terminated with a '\0'. You can you the size() function to find the legnth of the string. You would do that by nameOfString.size().

NathanOliver 429 Veteran Poster Featured Poster

try this

    if(test.find("open") != string::npos && test.find("door") != string::npos)
NathanOliver 429 Veteran Poster Featured Poster

The error you are getting is saying that it can’t find an operator << that will take a vector. The vector class does not have built in stream operators so if you want to pass a vector to << than you need to write your own function to do that.

sabrimev commented: You are saying I should oveload << operator? +0
NathanOliver 429 Veteran Poster Featured Poster

In you code you have this section now inside the second while loop.

if (order == ASCENDING) 
    if (*(j->next) < *(min->next)) 
        min = j;
else 
    if (*(j->next) > *(min->next)) 
        min = j;

You Would think that since the else is lined up with the first if that is what it is the else for but it is not. It is being treated as the else for the second if statement. This should get it working.

if (order == ASCENDING)
{
    if (*(j->next) < *(min->next)) 
        min = j;
}
else 
{
    if (*(j->next) > *(min->next)) 
        min = j;
}
NathanOliver 429 Veteran Poster Featured Poster

Well you can see if the line from the user contains the words open and door. Something like this

if(userInput.find("open") && userInput.find("door"))
    // open door

You can also get a little more complicated and make sure you find open before the word door.

NathanOliver 429 Veteran Poster Featured Poster

Line 8 should be i = head. Line 9 should be while(i->next != NULL). Line 23 should be i = i->next

NathanOliver 429 Veteran Poster Featured Poster

You can right your own pow function like this

int power(int base, int exponent)
{
    int result = base;
    for (int i = 1; i < exponent; i++)
    {
        result *= base;
    }
    return result;
}
NathanOliver 429 Veteran Poster Featured Poster

In your system you could have a CR/LF for \n. This would mean you have two charecters to get rid of. An easy way to get arroung this is to take in everything as a string and then convert the string to get what you need. If you want to use ignore than I would suggest using cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'). You do need the <limits> header to use this. What this says is to eat everything in the stream up to the maximum size of the stream untill you hit a \n, then consume the \n.

NathanOliver 429 Veteran Poster Featured Poster

You need to define the size of the 2d array. The way you have it now it should the compiler will make it 2X12 whn you actually need it to be 12X12. I would change it to int prodouct[ROW_SIZE][COLUMN_SIZE];

az-mi51 commented: Thanks! Worked Perfectly +0
NathanOliver 429 Veteran Poster Featured Poster

Static functions are generally used when you have static data members in a class and you want to be able to acess the static data. You have to have a satic function to acess static data since it is seperate from the objects of that class.

NathanOliver 429 Veteran Poster Featured Poster

What exactly is the error you are getting? Do you know where it is coming from? Posting 1400 lines of code with no indentation, no comments and poorly used variables names will not help you. You need to be specific with what you want. I doubt someone is going to go through 1400 lines of unformatted code for you.

NathanOliver 429 Veteran Poster Featured Poster

Have you steped through your code to see what the values are? You could also put in cout statements to print out the values in the function to see if the data is correct.

NathanOliver 429 Veteran Poster Featured Poster

Depending on what you can use I would use a map to store the posistion and the charecter that needs to be deleted. then you can use the map to delete the unwanted values and to restore them as well. I have implemeted a verxion of this that does work for the case you gave but I havent fully tested it. This should help you to see how everything is flowing. If you have a good debugger I would suggest stepping through the code to see what it is doing.

#include <iostream>
#include <string>
#include <map>

using namespace std;

int main()
{
    string name = "Mike W. Heintzman";
    string deleters = "mie";
    map <int, char> erased;

    cout << deleters << endl;
    cout << name << endl;
    // find all of the leters needed to be deleted and get the pos
    for(size_t i = 0; i < name.size(); i++)
    {
        for(size_t j = 0; j < deleters.size(); j++)
        {
            if(tolower(name[i]) == deleters[j])
                erased.insert(pair<int, char>(i, name[i]));
        }
    }
    // remopve the leters.  this will need to be done in revers order to preserve indexes
    map<int, char>::reverse_iterator rit = erased.rbegin();
    map<int, char>::reverse_iterator rend = erased.rend();
    while(rit != rend)
    {
        name.erase(rit->first, 1);
        ++rit;
    }

    cout << name << endl;

    // put leters back
    map<int, char>::iterator it = erased.begin();
    map<int, char>::iterator end = erased.end();
    while(it != end)
    {
        name.insert(it->first, 1, it->second);
        ++it;
    }

    cout << name;

    cin.get();
    return 0;
}
NathanOliver 429 Veteran Poster Featured Poster

! Is the factorial symbol. a factorial is defined as n! = 1 * 2 * 3 * ... * n-1 * n. Also 0! = 1. You will ned to write a function that will calculate that. If you know how to use a for loop it is pretty simple to do.

NathanOliver 429 Veteran Poster Featured Poster

All you need to do is use rand to get a random number in the range of your array and then use that number for the index of your array. Something like this:

cout << arr[(rand() % sizeOfArray)];
NathanOliver 429 Veteran Poster Featured Poster

Not to be rude AD but I'll do it for $4,000 USD. A guy has to make money :)

WaltP commented: Well it is rude, undercutting another member. That's no way to make friends ;-)) +14
NathanOliver 429 Veteran Poster Featured Poster

Well I know you want someone here to teach you but I dont see the point if there are perfectly good lessons somewhere else. http://www.cplusplus.com/faq/sequences/strings/split/ has a very good tutorial on how to accomplish what you need. I would suggest try using what is there and see what you come up with. If youy still need help post the code you have, any errors you are getting and/or what it should be doing and what it is not doing and you should get some help.

NathanOliver 429 Veteran Poster Featured Poster

Just get rid of the paramater in the function so it looks like this void draw(); and then change the function like this

void Creatures::draw()
{
    al_convert_mask_to_alpha(sprite, al_map_rgb(255,0,255));
    al_draw_bitmap(sprite, getX(), getY(), 0);
}

This will let you use the sprite variable of the class.

NathanOliver 429 Veteran Poster Featured Poster

you can also use division and the mod operator to do this. if you want to find out how may 10's you can get out of 87 it would look like this.

int amount = 87;
int tens = amount / 10;  // 87 / 10 = 8
amount = amount % 10;  // 87 % 10 = 7
// now amount holds the reaminder which is 7.
NathanOliver 429 Veteran Poster Featured Poster

You will want to use an array and a while loop to take in the input. to get the sum you would go through the array with a for loop and add all of the values.

NathanOliver 429 Veteran Poster Featured Poster

Well if you struct is called Student_info then you would use

typedef std::vector<Student_info> container_Student_info;

The syntax for this is

typedef std::vector<type_of_object_you_want_for_the_vector> name
NathanOliver 429 Veteran Poster Featured Poster

You should be able to get rid of lines 64-77. If you just keep track of the smallest difference like you are already doing inside your second for loop you should be okay.

NathanOliver 429 Veteran Poster Featured Poster

Well do you know what the formula for the fibonacci squence is? If not it is Fn = Fn-1 +Fn-2 where F0=0 and F1=1. so to get a fib number you have to take the previous number plus the number before the previous number. Can you see know how the code is working?

Grandiago commented: Thanks for the formula! Haha +0
NathanOliver 429 Veteran Poster Featured Poster

What happenes if you use an array instead of a vector?

Jsplinter commented: A simple, but good suggestion. Thank you! +0
NathanOliver 429 Veteran Poster Featured Poster

Using this approach if you use a loop to go back and ask the user for a number if they dont make sure you clear the error flags from cin. Otherwise the flags will stay set and you will always get the error message saying you didn't enter a number even though you did. I would like to add that there are better ways to go about doing this. Here is a little sinpet that will do a little error checking but there are better ways.

#include <sstream>
#include <iostream>
#inlcude <string>

using namespace std;  // just for the example

int main()
{
    float number;
    stringstream ss;
    string input;

    bool goodInput = false;

    while (!goodInput)
    {
        cout << "Please enter a decimal number: ";
        getline(cin, input);
        ss << input;  // puts input into the stringstream
        ss >> number;
        if(!ss.eof())  // was all we got an number?
            cout << "Please enter a decimal number!\n";
        else
            goodInput = true;
    }
    return 0;
}
NathanOliver 429 Veteran Poster Featured Poster

The expression of a switch statement must be of an integer type. That means you can use a single char but not a char array.

NathanOliver 429 Veteran Poster Featured Poster

So what do you have so far? We dont give out answers here we help oy uget the answer.

NathanOliver 429 Veteran Poster Featured Poster

Lines 12-15 need to come after line 18. Otherwise you are doing calculations with variables that havent been set yet.

NathanOliver 429 Veteran Poster Featured Poster

That is not true. Check out the code on this wiki page to see how they use virtual functions with only a pointer to the base class. http://en.wikipedia.org/wiki/Virtual_function#C.2B.2B

NathanOliver 429 Veteran Poster Featured Poster

Check this out if you are using windows. http://msdn.microsoft.com/en-us/library/windows/desktop/ff468802(v=vs.85).aspx

NathanOliver 429 Veteran Poster Featured Poster

That’s not really true. A reference is basically a pointer that the complier takes care of dereferencing for you. References also have limitations as that once they are referenced to and object they will always point to that object. Pointers can be change to point at different things at any time. When I code the only time I deal with actual pointers is when I am dealing with arrays. Otherwise I use references for function parameters if i need to be able to modify the variable. If I don’t need to modify the variable and it is a POD (plain old data) type then I will pass by value. If I am dealing with a non-POD type and I don’t need to modify the variable I will pass it by constant reference.

NathanOliver 429 Veteran Poster Featured Poster

a char* is considered a c-style string. It is just an array of characters. A char ** is and array of char* which is to say it is an group of c-style strings. The string type is an ogject created from the class string. These are two different things. This is a good page for learning about char arrays http://www.cplusplus.com/doc/tutorial/ntcs/
this is a goo page to learn about the string class http://www.cplusplus.com/reference/string/string/

NathanOliver 429 Veteran Poster Featured Poster

You want to write your own copy constructor for any class that contains pointers. The reason for this is that the default one the compiler makes only performs a shallow copy. This means that the copy will be exactly the same as the original. With pointers this is bad because if the copy gets destroyed which happens a lot with copies the pointer gets deleted. Once this happens the pointer in your original class can no longer be used safely and you might even get an exception when you delete the original class since you would call delete on the pointer again. IMHO I write my own copy constructor unless the class I am writing contains only POD types or classes that take care of themselves like vectors or strings.

NathanOliver 429 Veteran Poster Featured Poster

You are calling delete on number in your destructor for your palindorme class. You shouldnt do that. All members of the base class should be taken care of in the base class destructor like you have on line 13.

grh1107 commented: Thanks so much! I didnt know the base class took care of it i figured it would get a memory leak +0
NathanOliver 429 Veteran Poster Featured Poster

It all depends on how you code your program. If you have mechanisms in place in your code to handle error than you could try recover from that error. If that is not possible, than you could end the program gracefully and tell the OS that the program did not end successfully. Look up Try … Catch blocks to see what I mean about error handling. One example I can think of for this is an installation program. The program that is installing the software is chugging along when it runs into a problem that it can’t recover from. Wouldn’t it be nice if the installer could tell the OS that hey I could do what I was supposed to do so your new software isn’t going to work? Well that is exactly what you can do with a return statement. In the part of the code that is handling the error can’t fix it than it can return EXIT_FAILURE to the OS so that it know something is wrong. Now the OS know that the software won’t work and will give you options accordingly.

NathanOliver 429 Veteran Poster Featured Poster

It will if you do not have the string header in your struct header file. Please post what you have. Its hard to see your screen from here.

NathanOliver 429 Veteran Poster Featured Poster

After line 16 add cin.ignore(); . This is beacuse you are mixing inputs and this will clear the '/n' that is left in the buffer after the call to cin with >> . Not 100% sure how gets() works but this fixes the problem when trying to use getline()

NathanOliver 429 Veteran Poster Featured Poster

So what you need is more like prime factorization. There are many threads on this site that talk about that.

NathanOliver 429 Veteran Poster Featured Poster

to declare variables in c++ you do it as

int x, y;

So with that to declare a structure with an x and y variable you would do

struct Point
{
    int x, y;
}

Finally if you want to constuct you struct with values when you make it you need to add a constuctor

struct Point
{
    int x, y;
    Point(int x_, int y_) : x(x_), y(y_) {}
}

int main()
{
    int x = 5, y = 6;
    Point point(x, y);
}
triumphost commented: EXACTLY WHAT I WANTED!!!!! +6
NathanOliver 429 Veteran Poster Featured Poster

Well according to this the buffer needs to be 9 bytes long. Try changing datenew[8] to datenew[9] .

Diogo Martinho commented: Helpful +2
NathanOliver 429 Veteran Poster Featured Poster

Well you can use a counter variable and increment it until you find the word.

//...
int lineCount = 1;
while ( myfile.good() )
    {
      getline (myfile,line);
      if(line == word) {
             cout << "Walked was found on line " << lineCount;
              } else {
      lineCount++;
      cout << line << endl;
      }
    }
//...
Tom_Weston commented: Very thankful, and useful +1
NathanOliver 429 Veteran Poster Featured Poster

Well you can do like the standard library does and say that a iterator a pointer to the data of a class is only good until the next time you use the object.

NathanOliver 429 Veteran Poster Featured Poster

The first parameter of substr() is where you want to start so you don't want to start at the comma. you want to start at zero and go untill there is a comma. To do that you can do this.

string str1 = "hello,friend";
string str2 = str1.substr(0, str1.find(","));

this example will not delete any of the contents of str1 it will only copy the part before the comma into str2

Tom_Weston commented: Extremly Helpfull, Thank you for your contribution! +1
NathanOliver 429 Veteran Poster Featured Poster

if you want to get a positive number from the user try this out.

int number = -1;
while(number < 0)
{
    cout << "please enter a positive integer: ";
    cin >> number;
}
myrongainz commented: thanks man +0
NathanOliver 429 Veteran Poster Featured Poster

If you are trying to ask how do you get the index of the element if it is already in the vector than you can get it in you if statement on line 68. after line 70 just add a line to assign i to some variable you crated at the start of main. Something like indexOfAlreadyExistingWord. I am a little curious as to how your instructor wants this done. There seams to be a lot of unneeded code. If I was to do this i would use a map with a key value of type string and a mapped value of type int. Here is an example of how I would do this

#include <map>
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main()
{
    string word;
    size_t pos;
    map<string, int> wordList;
    ifstream fin("const.txt");
    while (fin >> word)
    {
        while ((pos = word.find_first_of(",.;:()123456789", 0)) != string::npos)  // this gets rid of puntuation and numbers
            word.erase(pos, 1);
        if (word.empty())
            continue;
        wordList[word] += 1;  // ads the word to the list and incremetns the counter
    }
    cout << "The number of words foud is " << wordList.size() << endl;
    cin.get();
    return 0;
}
TheNNS commented: thanks man +9