NathanOliver 429 Veteran Poster Featured Poster

okay so don't pass in an array of objects but pass in a single object. modify your coord class to just take in a single cord object in the collision function also changing the code to not use [] in your if statemnt. then in your main function just call asteroid[i].collision(asteroid[i+1]);

NathanOliver 429 Veteran Poster Featured Poster

why exactly are you passing an array to your collision method? wouldn't you just want to pass one object or are you trying to see if everything in that array will collide with the calling object?

NathanOliver 429 Veteran Poster Featured Poster

the problem is when you pass an array to a function the actual thing that gets passed is a pointer to the first element of the array. the function doesn't know its an array so it doesn't know that he address after the pointer are part of the array. there are to ways to go about this dilemma. first you could pass the size of the array to the function so it knows hat the upper bound is.

int size = 0;
cout << "please enter the number of employees you want to enter: ";
cin >> size;
char * employees = new char[size]; // create a dynamic array
sort(employees, size);
//...

or you could use a sentinel value at the end of the array and check for it while parsing through the array.

//in function for sorting
void sort(char temp[]);
{
       int i = 0;
       while (temp[i] != '/0')
       {
              // your code here
       }
}

i prefer to use the first case becuase it is much easier for int arrays then using a sentinel.

NathanOliver 429 Veteran Poster Featured Poster

a lexer is a program that runs through text and converts it into something you can use in your program an example would be a program that lets you input something like 5x^5 - 3x^3 + 20x^2 +5x -15. it would convert all of those into tokens that your program can use to output a solution. at least this is what i believe it is.

NathanOliver 429 Veteran Poster Featured Poster

If you already know what files you are going to use than i would just use

ofstream outFile("Data.txt");  
ifstream inFile("Maze.txt");
NathanOliver 429 Veteran Poster Featured Poster

to dived you use / not \. also i(...) is not valid. if you want to multiply i by that quantity you have to do i * (1.0 / i) . Also please use code tags. the link to explian them is http://www.daniweb.com/forums/announcement8-3.html

NathanOliver 429 Veteran Poster Featured Poster
#include statements

using statements

global vars ie 
ofstream fout;
or
ifstream fin;

function prototypes

int main()
{ //...

this is the style i use

NathanOliver 429 Veteran Poster Featured Poster

you are getting a overflow and that is what the return value becomes. your call to pow when k=10 for instance returns 1.5556504132421497887188538979512e+174 but the max value for a float is 3.40282e+038. i would try using type double which has a max of 1.79769e+308.

NathanOliver 429 Veteran Poster Featured Poster

where are you getting the isblank() function from?

NathanOliver 429 Veteran Poster Featured Poster

well first of your calling getline twice. once after your for statement and once after your if statement. also you should not use eof() while reading to the end of the file. you can search around and find some good links about that. i would get rid of the for loop and just use a while loop like

while (getline(ifs1, s1) && getline(ifs2, s1))
{
       // your code here
       i++;  //  this will increment i so you don't need the for loop.
}
NathanOliver 429 Veteran Poster Featured Poster

yeah your setting a pointer equal to another. classes don't need an operator=() function for that its handled by the compiler.

NathanOliver 429 Veteran Poster Featured Poster

I'm not sure about making it a void pointer but you should be able to make a weapons class that is the bass for all of your specific classes and then make a pointer of the base class and re assign it with your specialized class pointer. this would be more inline with c++ OOP style.

class Weapon
{
       // all standard functions and variables.
}

class Flamethrower : public Weapon
{
       //  overide all functions from wepon that are specific to a flamethrower.
}

int main()
{
       Weapon * weapon;
       // later on
       Flamethrower * temp = new Flamethrower;
       weapon = temp;
       // ...
}

this will require the use of virtual functions and may be a little more than you are looking for but i believe this will work.

NathanOliver 429 Veteran Poster Featured Poster
NathanOliver 429 Veteran Poster Featured Poster

i have seen this in my debugger and have no idea what causes it. it might be that there there is a limit on how far the debugger goes to drill down the information of a variable. also under the watch list it has tabs for local, auto witch might also change what is shown.

also my signature doesn't apply to your code. its just to explain to people if they have using namespace std; later in there code they don't need to write std::cout.

NathanOliver 429 Veteran Poster Featured Poster

are you actually getting compiler errors or is it just not letting you see the values of some of the objects/variables while debugging?

NathanOliver 429 Veteran Poster Featured Poster

alright the problem is you are using endl after each name so it wil display each name on a seperate line. if you want to displa it as Last, First then this should work well for you.

void showArray( string names[], int NUM_NAMES )
{
     for(int count= 0; count<NUM_NAMES; count+=2)
     {
          cout << names[count] << ", " << names[count +1] << endl;
     }
     cin.get();  // <-  use this instead of system("pause")
}
NathanOliver 429 Veteran Poster Featured Poster

could you post an example of the code you are having problems with?

NathanOliver 429 Veteran Poster Featured Poster

could you please post your code for your showArray() function. it looks like the problem will be in there.

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 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

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

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'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

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

well it could look something like

vector<string> foo(vector<string> foobar);
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

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 i got it running. i deleted the #include "stdafx.h" and changed qu_main(argc, argv) to int main()

NathanOliver 429 Veteran Poster Featured Poster

that is the problem

cout << 'a';  //  good
cout << ' ';  //  good
cout << 'ab';  //  bad
cout << '  ';  // bad
NathanOliver 429 Veteran Poster Featured Poster

on lines 3-6 you are checking if the accnum==accountnum and if it doesnt return -1. so one the frist time if the number isnt equal then it will return -1. i would suggest re writting the loop as

for (int i = 0; i < 1000; i++)
{
       if (accnum == accountnum[i])
              return i;
}
return -1;
NathanOliver 429 Veteran Poster Featured Poster

sorry one other mistake starting at line 5

int *counter = new int;
*counter = 0;
//...

this will fix the problem.

NathanOliver 429 Veteran Poster Featured Poster

sorry i had a coding error line 18 should be (*counter)++ see if that fixes the problem

NathanOliver 429 Veteran Poster Featured Poster

well if you are using just one array to store all the account numbers then

void create_account(int array[1000], int * counter);
       
int main()
{
       int * counter = 0;
       int accountnum[1000];
       //.. do your menu
       // when the user selects to create an account
       creat_account(accountnum, counter);
}

void creat_account(int array[1000], int * counter)
{
       int temp;
       cout << "please enter an account number: ";
       cin >> temp;
       array[(*counter)] = temp;
       *counter++;
}

this will keep track of how many number are in the array and every time you need to add a number to the it will put it in the right spot and update the number of numbers are in the array.

NathanOliver 429 Veteran Poster Featured Poster

oh sorry well you can do that on the heap then like

//...
int a;
fin >> a;
string * S = new string[a];
//...
NathanOliver 429 Veteran Poster Featured Poster

sorry didn't totally read your post. it sounds like you need to be writing a function for getting the account numbers in that case you could have the array and a variable that holds how many entries are in the array in your main function. then you could pass the array and the counter variable into the function and have it ask for the account number. then store the account number into the array at the counter + 1 and then increment the counter. in order to do this you will either have to pass the counter variable into the function by reference or as a pointer or have the function return counter + 1 and store that in counter. i hope i'm making sense with this.

NathanOliver 429 Veteran Poster Featured Poster

you can have the input statement inside the loop

int accnum;
int accountnum[1000];
for (int i = 0; i < 100; i++)
{
       cout << "please enter an account number: ";
       cin >> accnum
       accountnum[i] = accnum;
}
NathanOliver 429 Veteran Poster Featured Poster

you really don't need to declare the size of the string when you create it. it is good practice to do so but the string will automatically re size itself when it needs to do so. this will make a little performance hit though.