NathanOliver 429 Veteran Poster Featured Poster

the compiler i am using is MS C++ 2005. it runs better on my machine than 2008 does and i started with MS C++ 6.0 so it was a good and easy transition for me. the minimize code feature is really nice as well.

NathanOliver 429 Veteran Poster Featured Poster

the 1120 error comes from the 2019 error. if you get a LNK2019 error you will always get a LNK1102 error

jonsca commented: Good insight, I had forgotten +2
NathanOliver 429 Veteran Poster Featured Poster

the problem is the chicken and the egg paradox. what comes first in your code A or B?. if A is first and A uses B then the compiler goes to B to find out what B is but B has A in it and A isn't finished so it doesn't know what A is yet either. the same thing will happen if B is first. unfortunately there is no solution for this problem. it just isn't possible in c++ right now. you can have A have a B as long as B doesn't have an A in it or the other way around with B but A cant have B when B has A in it. i really hope I'm making sense

NathanOliver 429 Veteran Poster Featured Poster

to expand an array you could do this in your code

int MAX_SIZE = 256;                  // just using 256 as an example
int arraySize = MAX_SIZE;
int * array= new int[MAX_SIZE];
//  rest of your code
//  while in your loop of entering data
if(arraySize % MAX_SIZE == 0)
{
       MakeArrayBigger(array, arraySize, MAX_SIZE);
}

//  definition to MakeArrayBigger
void MakeArrayBigger(int * array, int size, int incrementSize)
{
       int * temp = new int[size + incrementSize];
       for (int i = 0; i < size; i++)
       {
              temp[i] = array[i];
       }
       delete [] array;
       array = temp;
       delete [] temp;
}

this is just a quick dirty example but i think you will get the jist of it

NathanOliver 429 Veteran Poster Featured Poster

there is a feature in vista that will use a usb jump drive as a sort of ram but this is very slow. maybe a better way would to use an esata connection to some flash based memory. just a thought

NathanOliver 429 Veteran Poster Featured Poster

well to keep kicking the dead dog. Fboady it is true that a 32bit int is aprox -2 bil to 2 bil but 100! is 9.3326215443944152681699238856267e+157 which is way out of range for an int on even a 128 bit system.

NathanOliver 429 Veteran Poster Featured Poster

after your cin >> jourB call cin.get(). that should get rid of your problem.

#include <iostream>
#include <string>

using namespace std ;

void foo();

int main()
{
	string temp;
	int a;
	cout << "this program is to demonstrate cin.getline()\n";
	cout << "\nplease enter a integer: ";
	cin >> a;
	cin.get();  //<-  gets rid of the newline in the buffer
	foo();
	cin.get();
	return 0;
}

void foo()
{
	string temp;
	cout << "Please enter a sentence: ";
	getline(cin, temp);
	cout << "\nThis is what i received: " << temp;
}
NathanOliver 429 Veteran Poster Featured Poster

i have no idea. what i do is go put a breakpoint around the code i dont think is working and then step through the code line by line and see what happens to the variables

NathanOliver 429 Veteran Poster Featured Poster

not in the function but in the code that the function was called from or from before that. even though im putting my getline function is in a different function it is still not working because of my cin >> a call.

#include <iostream>
#include <string>

using namespace std ;

void foo();

int main()
{
	string temp;
	int a;
	cout << "this program is to demonstrate cin.getline()\n";
	cout << "\nplease enter a integer: ";
	cin >> a;
	foo();
	cin.get();
	return 0;
}

void foo()
{
	string temp;
	cout << "Please enter a sentence: ";
	getline(cin, temp);
	cout << "\nThis is what i received: " << temp;
}
NathanOliver 429 Veteran Poster Featured Poster

i would set sumOfTheScores to 0 when you declare it and then see what happens. ie. int sumOfTheScores = 0;

NathanOliver 429 Veteran Poster Featured Poster

in your code do you take in something with cin like cin >> foo; i have changed my sample program so you can see what happens if you take in input with cin >> and then call getline. the problem is there is a carriage return in the buffer so getline will grab that and return nothing.

#include <iostream>
#include <string>

using namespace std ;

int main()
{
	string temp;
	int a;
	cout << "this program is to demonstrate cin.getline()\n";
	cout << "\nplease enter a integer: ";
	cin >> a;
	cout << "Please enter a sentance: ";
	getline(cin, temp);
	cout << "\nThis is what i recived: " << temp;
	cin.get();
	return 0;
}
NathanOliver 429 Veteran Poster Featured Poster

what does prompst(18); do?

NathanOliver 429 Veteran Poster Featured Poster

im not sure what is going on then. could you re post your code you have now. also what compiler are you using?

NathanOliver 429 Veteran Poster Featured Poster

also as a side note you should avoid using .eof()
http://www.daniweb.com/techtalkforums/post155265-18.html

NathanOliver 429 Veteran Poster Featured Poster

you have no braces around your while function. should be

while (i < NUM_EXAMS)
{  // <-  dont forget these for multy line statements.
        input >> examScore[i];
        sumOfTheScores += examScore[i];
        i++
}  // <-  same here.
richman0829 commented: Good catch! +1
NathanOliver 429 Veteran Poster Featured Poster

oops sorry my bad. here is a little program for you to see how getline works.

#include <iostream>         //
#include <string>           //  see how i have no .h after the name of the header

using namespace std ;

int main()
{
	string temp;
	cout << "this program is to demonstrate cin.getline()\n";
	cout << "Please enter a sentance: ";
	getline(cin, temp);
	cout << "\nThis is what i recived: " << temp;
	cin.get();
	return 0;
}

also you are using depreciated headers. iostream.h, fstream.h, string.h should all not have the .h after them. this is not to say that you don't need them after your own header files. you just don't need them for these. maybe someone else can explain this better im not sure if im getting it right.

NathanOliver 429 Veteran Poster Featured Poster

well im not sure if you have to have a cout statement to have a cin statement but cin.getline(entryA, "\n"); should work to get in a lot of input.

NathanOliver 429 Veteran Poster Featured Poster

also you do not have the definition of train(int) anywhere. your compiler doesn't know what to do because you didn't write the code for it.

NathanOliver 429 Veteran Poster Featured Poster

the easiest way to handle all different types of inputs is to receive them as strings and then go through them and figure out what the user entered. there are plenty of functions to help with this. the function isdigit() will test to see if the character is a number. isalpha() will test if its a letter. these functions are defined in the header <locale>. a little demonstration of receiving input as a string and converting it to a number is:

#include <iostream>
#include <locale>
#include <cstdlib>

using namespace std;

int main()
{
       int i = 0;
       int numberInput;
       char input[80];  // used for the user input
       char converter;
       cout << "please enter a number: ";
       cin.getline(input, "\n");  //  receives the entire input into input
       while (isdigit(input[i]))
       {
              converter[i] = input[i]
              i++;
       }
       convert[i] = "\n";
       numberInput = atoi(converter);
       cout << "\nyou entered: " << numberInput;
       return 0;
}

this is just a quick little example of how to get input as strings. of course there are much better ways to do because this wont work with negative numbers. this is just to give you an example how the basics work.

Ancient Dragon commented: Nice answer. +25
Iamthedude commented: Thanks for the assistance +0
NathanOliver 429 Veteran Poster Featured Poster

i saw your link just a few minutes ago Dave and it is a very good idea. i had always wondered why it didn't work right sometimes and this really helped.

NathanOliver 429 Veteran Poster Featured Poster

just for giggles can you try

while (index < NUM_PROG && cin >> prog[index])
{
       if(strcmp(prog[index], "-1")
              break;
       index++;
}
NathanOliver 429 Veteran Poster Featured Poster

the problem is that you are displaying the value of the ifstream reference. your while loop is good but you need to store the data into some other variable and then display it via cout. such as:

//...
while (!myfile.eof())
{
       myfile.getline(line, "\n");
       cout << line << "\n";
}
//...

i used getline here so if there are spaces in the line of text it ill keep reading until the end of the line. hope this helps you out.

NathanOliver 429 Veteran Poster Featured Poster

yes you need to declare first last and x inside your function in order to use them. what SasseMan was saying is you need to define the operator = for your class. it is a god idea to write your own because the default just dose a shadow copy of the class and this could lead to problems latter on. in his function that he gave you he just had cStudent & operator=( const cStudent & ); . when you declare a function you don't have to supply a variable name unless you are writing it inline. if you write it like your other functions where the definition follows directly after the declaration then you will need to have a variable name.

class foo
{
       //...
       cStudent & operator=( const cStudent & );
       //...
};

cStudent & cStudent::operator=(const cStudent & student)
{
       //  define function here.
}

or

class foo
{
       //...
       cStudent & operator=( const cStudent & student)
      {
              // define function here
       }
       //...
};
NathanOliver 429 Veteran Poster Featured Poster

I'm not seeing a main function anywhere. do you have this code in a main function?

wolfkrug commented: Thanks so much! +0
NathanOliver 429 Veteran Poster Featured Poster

i would have sGuess be a char variable in this case. as stated earlier there may be multiple occurrences of the guess letter in the random word. for that reason you would either need another array to keep track of the positions in the random word or you could use a flag system if you are using a class. a simple way of doing this might be

void foo()
{
       char guess;
       string word;
       bool complete = false
       // get word from function
       int wordLength = word.length();
       int * correctPlaces = new int[wordlength];
       for(;;)
       {
              cout<< "\nPlease enter a guess: ";
              cin >> guess;
              for (int i = 0; i < wordLength; i++)
              {
                     if (guess == word[i])
                            corrrectPlaces[i] = 1;
              }
              cout << "\nOkay this is what you have so far";
              for (int j = 0; j < wordLength; j++)
              {
                     if(correctPlaces[j] == 1)
                            cout << word[j];
                     else
                            cout << "_";
              }
              for (int k = 0; k < wordLength; k++)
              {
                     if (correctPlaces[k] == 1)
                            complete = true;
                     else
                     {
                            complete = false;
                            break;
                     }
              }
              if (complete)
                     break;
       }
}

this is just a quick example of how to deal with multiply same letters in a string. depened on how you application is written this might not work for you but this should get you going

NathanOliver 429 Veteran Poster Featured Poster

there is a function tolower that you can use to help you with this.

NathanOliver 429 Veteran Poster Featured Poster

the problem you are having is on line 19. when you declare a 2d array you declare the rows and columns of the array. your statement int PlayerInfo[MAX_PLAYERS][pInfo]; is saying define an array of 32 rows and pInfo columns. since pInfo is a type and not a value you can not use it in this way. if you want to crate an array of pIfos you could use

pInfo players[MAX_SIZE];

this would create an array of 32 pInfos types. if this isn't what your looking for let me know.

NathanOliver 429 Veteran Poster Featured Poster

i would do something along the lines of cout << *place.GetLex() << endl;

NathanOliver 429 Veteran Poster Featured Poster

the problem is on line 70 and 76. on line 76 you have cout<<name.top()<<" "; . here you are outputting the top object int the stack which is of type Lexeme. you either need to define and operator<<() function for your class or call an accessor like cout<<name.top().getLex()<<" "; . the same goes for line 70 when you are calling the list object which is of type Lexeme. hope this makes sense to you.

NathanOliver 429 Veteran Poster Featured Poster

it looks like you are doing your checking of the guess in the blankspaces function. so if that is the case then i would add a line in you else statement of the if(flag) statement to increment inCorrectGuess

//...
if (flag)
{
       //...
}
else
{
       cout << "_";
       inCorrectGuess++;  // <-  records a wrong guess.
}
//...

that should help you out with the incrementation. also please use code tags when posting code.

NathanOliver 429 Veteran Poster Featured Poster

no problem

NathanOliver 429 Veteran Poster Featured Poster

well it could look something like

vector<string> foo(vector<string> foobar);
NathanOliver 429 Veteran Poster Featured Poster

could we see some code? its kinda hard to see you computer screen from here

NathanOliver 429 Veteran Poster Featured Poster

well one good practice to get into is to set your pointer to null after you delete it

int * a = new int[30];
delete [] a;
a = NULL;
//or
a = 0;

this will make sure the the pointer no longer points to where it used to and will also make it safe to delete again. with the delete function if you call it on a pointer you have already deleted than it will cause an error but calling delete is guaranteed to be safe. the delete function just frees the memory back up to the system. it doesn't actually delete the information in the memory.

NathanOliver 429 Veteran Poster Featured Poster

have you tried using vectors? you could store the separate strings in a vector just like an array and pass the vector into the function. also is your function did you want to take in an array of strings or a single string at a time. you only need one string at a time i would just write string foo(string foobar)

NathanOliver 429 Veteran Poster Featured Poster

yes the while statement i wrote will check to see if the use entered Y or y. if the user enters either of the toughs the do while loop will continue. all other inputs will stop the loop and end the program.

NathanOliver 429 Veteran Poster Featured Poster

you need to move your declaration of y to be before the do statement on line 23. the reason is that when the compiler hits the while statement it hasn't seen the deceleration for y so it doesn't know what it is. also a easy way to do the while statement would be

while(yesorno == 'Y' || yesorno =='y')

this will make sure that only a Y or a y will continue the code and all other inputs will be treated like a N or n

NathanOliver 429 Veteran Poster Featured Poster

the reason that you can go beyond the array size is that in c++ it is leagal to increment the pointer past the size of the array. its a through back to c. you cant start before the array like index = -1 but if the size of the array is 2 it is legal to go the index = 2.

char temp[1];
temp[-1]  // cannot be done
temp[1]  // okay even though the data is only in temp[0]
NathanOliver 429 Veteran Poster Featured Poster

i assume you didn't read the second post on the page where it says we only give help on homework to those who show effort. do you have any code and having a problem with it? do you have any idea what the logic should be? variables?

NathanOliver 429 Veteran Poster Featured Poster

i use 2 computers. one desktop and one laptop. to be fair though the desktop has 3 screens that i use :)

NathanOliver 429 Veteran Poster Featured Poster

woot 7 right. and im a leader with a 64. not quite sure what the scale is out of though.

NathanOliver 429 Veteran Poster Featured Poster

also you have not terminated the array with a newline value so cout does not know where the end oh the char array is.

NathanOliver 429 Veteran Poster Featured Poster

try giving this a shot
horse.h

//Horse.h
#ifndef HORSE_H_INCLUDED
#define HORSE_H_INCLUDED

class Horse
{
    public:
        Horse(int age) : itsAge(age) {}

        virtual void operator=(Horse& rHorse) {itsAge = rHorse.itsAge;}

    private:
        itsAge;
}

#endif // HORSE_H_INCLUDED

pony.h

//Pony.h
#ifndef PONY_H_INCLUDED
#define PONY_H_INCLUDED

#include "Horse.h"

class Pony : public horse
{
    public:
        Pony(int age, int color) : itsColor(color) {itsAge = age;}
        virtual void operator=(Pony& rPony) {itsAge = rPony.itsAge; itsColor = rPony.itsColor;} 

    private:
        int itsColor;
}

#endif // PONY_H_INCLUDED
NathanOliver 429 Veteran Poster Featured Poster

on this line

while ((sort != 'chocolate') && (sort != 'carrot') && (sort != 'custard') && (sort != 'fruit') && (sort != 'coffee')

you are using single quotes for the words. you need to use double quotes.

while ((sort != "chocolate") && (sort != "carrot") && (sort != "custard") && (sort != "fruit") && (sort != "coffee")

also since this thread is solved i would suggest starting a new one if you have any other problems.

NathanOliver 429 Veteran Poster Featured Poster

you don't need to define each class in the same header file. all you need to do is include the header file from the base class into the child class header file. since you are use inclusion guarding you wont need to worry about multiply inclusions in you main.cpp file.

NathanOliver 429 Veteran Poster Featured Poster

well with polymorphism you do need to use virtual functions in order for the program to know which functions to use. since it isn't virtual it is calling the horse operator=() function instead of the pony's operator=() function. there is a little more overhead with virtual function because of the v table implementation but that is one of the trade offs with polymorphism.

NathanOliver 429 Veteran Poster Featured Poster

sorry in main it should be

//...
DayOfYear DOY(day);
DOY.print();
//...
NathanOliver 429 Veteran Poster Featured Poster

well you being asked to provide the information in the constructor so you should have something like

class DayOfYear
{
public:
       DayOfYear(int day) { day = y; }
       //...
};

the you initilize the class like

int main()
{
       int day;
       cout << "enter the day: ";
       cin >> day
       DayOfYear(day);
       DayOfYear.print();
       return 0;
}

hope I'm explaining this okay for you.

NathanOliver 429 Veteran Poster Featured Poster

well after rechecking my code i am getting a compounding error with the division of floating point number and after a 12 digit number there is enough error each loop that it makes finding a 13 digit or longer root impossible. after pulling out my old math book for a refresher in logarithms i have decide that this is much faster and smaller unfortunately it goes against the OP's problem of not using the pow function

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	long double number, root, answer;
	cout << "enter a number for the root: ";
	cin >> number;
	cin.get();
	cout << "enter the root you wish to find: ";
	cin >> root;
	cin.get();
	answer = pow(10, log10(number)/root);
	cout.precision(20);
	cout << root << char(251) << number << " = " << answer << "\n";
	cin.get();
	return 0;
}
NathanOliver 429 Veteran Poster Featured Poster

hi all. I'm not sure if its possible but can you call a different constructor inside a constructor of a object? ie can i have different constructors call a single constructor to set up the object

class foo
{
public:
       foo(int)
       foo(double)
       //...
};

foo::foo(int number)
{
       this = foo((double)number);  // ?
}

any help would be appreciated. thanks