NathanOliver 429 Veteran Poster Featured Poster

Your multiplier array and your code to populate it is the problem. The array is of type int but you are trying to store a double into it. This will just cause a truncation problem for storing the values. The main issue is in your for loop on line 61. You set y to .01 which the compiler will make equal to 0 for an int data type. Since y is zero and you are multiplying it by 10 you will always get zero and have an infinite loop. I would suggest you change the type of the array you are using and you will also need to rewrite the code to fill the array. For filling the array I would do something like this

// in class body
Double Multipliers[10];
//...

// in constructor
Multipliers[0] = .01;
for (int i = 1; i < 10; i++)
    Multipliers[i] = Multipliers[i – 1] * 10;
//…
NathanOliver 429 Veteran Poster Featured Poster

I did a google search and it looks like this happenes when either or both g++ and gdb are not installed

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

The problem you are having is that you are using an unsigned integer type. When you underflow that type it wraps around to the largest number it can be. You have to be very careful when you get towards the min or max number that your type can hold because sometimes this will happen. One nice feature of this is that if you want the largest number that an unsigned type can hold you can always subtract one from 0 and you will get the max.

Unsigned int: 0 - 1 = 4294967295

Unsigned int: 4294967295 + 1 = 0

NathanOliver 429 Veteran Poster Featured Poster

the string type is part of the standard namespace. if you are going to use types from the std namespace in a header file than you will either need to fully qualify the name like std::string or you could use a using directive like using std::string;. I would not use using namespace std; in a header file and use it very sparringly in cpp files. Why import the whole namespace when you only need a few things?

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

if you are having a problem with file IO give this page a shot. http://www.cplusplus.com/reference/iostream/ifstream/

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

My suggestion is pretty much the same as Schol-R-LEA's. I would you a sieve of Eratosthenes to generate all number between 2 and the upper limit for your test. After that I would check and see if the number inputted is in the list. If it is then divide the number by 10 and then check again. Keep doing that until the number to check is equal to one. If you find a number that is not prime before you reach one then the number would not be prime per your conditions. You could do this with a loop but I think recursion is better suited for the task.

NathanOliver 429 Veteran Poster Featured Poster

I know you already have a lot of code invested in this but it might be worth it to change what you are using for your arrays. I would suggest using a vector. You dont ned to worry about any memory managment or sizing issues. Why rewrite it if you dont have to.

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

What error are you getting? To try and make finding the problem easier you should try to skim the code down to the smallest thing you can get that still produces the error. Try to fix that and then implement the fix into the larger code that you have. Seeing 800 lines of code with virtually no comments and no mention of what the error is wont get you very far.

NathanOliver 429 Veteran Poster Featured Poster

you should be initializing it your constructor

NathanOliver 429 Veteran Poster Featured Poster

I believe the problem lies in the fact that you only have 1 paramater in your function. From functions I have seen you need to have at least one paramater that does not have a default paramater

NathanOliver 429 Veteran Poster Featured Poster

Do you know how to use arrays?

NathanOliver 429 Veteran Poster Featured Poster

what do you have right now?

NathanOliver 429 Veteran Poster Featured Poster

Well if you want to parse a string the best way i can think of is to you a stringstream. You get the input from the user using getline like you have and then you would put the string into the stringstream. After that you would output all of the differnt parts into som sort of contianer. After that you just go through the continaer and handle accordinginly. Here is a little sample of how to do that.

// to break a up string
#include <vector> // for vector
#include <sstream> // for stringstream
#include <iostream>
#include <string>

int main()
{
    std::stringstring ss;
    std::string input, temp;
    std::vector<string> comand;
    std::cout << ">: ";
    std::getline(cin, input);
    ss << input;
    // brak up line and put each part into the vector
    while( ss >> temp)
    {
        comand.push_back(temp);
    }
    // display vector
    for(size_t i = 0; i < comand.size(); i++)
        std::cout << comand[i] << std::endl;
    std::cin.get(); // pause program
    return 0;
}
NathanOliver 429 Veteran Poster Featured Poster

What happenes if you set pixels to null in your constructor?

Pixels = NULL;
NathanOliver 429 Veteran Poster Featured Poster

Do you know how to use cin and cout? Have you heard of get() and/or getline()? Using those you can take anything in from the user you want in almost any way you want it. Generally what you should do is read in the entire line and then parse out the line into the comands and data that was provieded. Than you can go through the seperated data to find out what you should do.

NathanOliver 429 Veteran Poster Featured Poster

The reason you are having an issue is you are setting youngest equal to 0 before you start the for loop and as long as you have valid data you shouldnt have an employee with a zero age.

// change
youngest = 0;
// to 
youngest = recordlist[0].age

The condition is your for loop looks weird as well as the if statement fot the youngest part. You should use the exact same loop and if statement that you used to find the oldest for finding the youngest. The only difference is the you need to change > to < in the if statement and change oldest to youngest

 int youngest = recordlist[0].age;    // Determine and print youngest employee(s):  
 for (int i=0; i<recordlist.size(); i++) 
 {
     if (recordlist[i].age < youngest)
         youngest = ecordlist[i].age
 }
NathanOliver 429 Veteran Poster Featured Poster

are you using the string class or are you using a char array?

NathanOliver 429 Veteran Poster Featured Poster

To continue Tumlee's point if you want the data to be in an unbeadable form than you are going to need to learn how to create a data structure and then write the structure to file in binary. One cavet of this is that text is still text in binary.

NathanOliver 429 Veteran Poster Featured Poster

Since you are dealing with the string class what happenes if you change it from 1 and 0 to '1' and '0'

s += '1'
s += '0'
NathanOliver 429 Veteran Poster Featured Poster

What happens if you change your for loop to

for(markit = mark.begin(), courseit = course.begin(); markit < mark.end(), 
courseit < course.end(); ++markit, ++courseit)

I think the problem you are having is that you are trying to use iterators from temporary objects but I could be wrong.

NathanOliver 429 Veteran Poster Featured Poster

So you have a file that is 100MB large and you want to search it for a specific string? how are you storing yor string in your function? do you store a new string for each line in the file or are you putting the entire file into one string? what do you want to do with the string that you find the matching substring in?

NathanOliver 429 Veteran Poster Featured Poster

The problem you are having is ring is declared as an int but you are trying to use it as an int array.

NathanOliver 429 Veteran Poster Featured Poster

All clear does in this is remove any error flags that might be present in the stringstream object. If you want to empty the stringstream then you want to use the ignore() function. Try replacing ss.clear() on line 59 with ss.ignore(std::numeric_limits<streamsize>::max()); . You will need to include the <limits> header for the numeric_limits() function.

NathanOliver 429 Veteran Poster Featured Poster

Ever think about just including the cctype header in your project? If you dont want to do that then what you have looks good as long as CCTYPE is defined in the cctype header file. If you want to check if something is not defined then you would use #IFNDEF something

NathanOliver 429 Veteran Poster Featured Poster

You do not need a while loop in your function. Think about the steps you need to do to get a factorial. There should be a conditional statment in a secursive function to check if you have reached a base case. There should be a call to the function itself if you have not reached a base case. Generally you do not use a loop in a recursive function.

NathanOliver 429 Veteran Poster Featured Poster

You cant compare char strings like that. You have to use the strcmp() function. I you want to compare strings with the logical comparison operator than you could use the string class available from <string> or you have to write your own.

NathanOliver 429 Veteran Poster Featured Poster

Thanks firstPerson I forgot about the special casses.

NathanOliver 429 Veteran Poster Featured Poster

Yes you can Overide any operator you want. This can be done globally or at a specific level.

NathanOliver 429 Veteran Poster Featured Poster

@ adityatandon if you include a check for a space and a \n then you will get the right amount of words.

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

Well you can use a counter variable and every time you read a string increment the counter by 1.

NathanOliver 429 Veteran Poster Featured Poster

I belive you need to increment j after line 27 and before line 28. Otherwise you are always starting back at the same place.

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

Well for starters an int can not hold decimals. A float or a double is required for that. you can do this with int's if you know how to use the % operator.

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

If you had

char ch = 'a';
a += 2;
cout << a;

It would display c . This is because a char is the same as a 1 byte integer. It actually holds a number between 0 and 255. If you are dealing with ascii characters then 'a' is equal to 97. If you add 2 to that you get 99 which is the value of 'c'.

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

Yes.

NathanOliver 429 Veteran Poster Featured Poster

The problem with you logic is that i is starting out at 0 not 1. Since 0 is a number you have 0, 1, 2, 3, ... 98, 99. The reason i is 100 is because when i is 99 it get incremented to 100 and then it is checked against the condition of the for loop. It fails so the loop end but that doesn't change the fact that i is still 100.

NathanOliver 429 Veteran Poster Featured Poster

What about the open brace on line 393?

NathanOliver 429 Veteran Poster Featured Poster

I didn't see a matching closing brace from then opening brace on line 147

NathanOliver 429 Veteran Poster Featured Poster

Well I'm not looking at all of this code that's what using a debugger is for but at first glance line 47 is wrong. You are returning an object that doesn't exist. What are you using to compile your code? If you are using an IDE they normally have built in feature to step through your code and you can see what is going wrong. .It is very helpful and you can really learn from it.

NathanOliver 429 Veteran Poster Featured Poster

if you want to get a whole of text uasing cin you need to use getline()

NathanOliver 429 Veteran Poster Featured Poster

LL is a pointer so you would ned to write

p->ll->appened("stuff");
NathanOliver 429 Veteran Poster Featured Poster

A linked list can only contain elements of the same type. You could make a list of list like

std::list< std::list< int > >;
NathanOliver 429 Veteran Poster Featured Poster

Recursion is a function calling itself. This will show you recursion. If you look above that post you will se an iterative version of the same code.