CoolMaster Posted April 25, 2007 Posted April 25, 2007 (edited) I think I got it, before the counter i made display gen like this displaygen(generation, initrow, initcolumn); but in the loop i replaced it with (regen,initrow,initcolumn); and I got rid of the second paramter in the display function, didnt get any errors altho it still wont change the function, perhaps it's something wrong with my generate function? void generate (int generation[maxrow][maxcolumn], int nextgen[maxrow][maxcolumn], double like, int initrow, int initcolumn) { for(int a = 0; a < initrow; a++) { for (int b = 0; b < initcolumn; b++) { if(generation[a][b] == star) { nextgen[a][b] = slash; } } } } btw Im sorry Im frustrating to deal with, it's been 9 hours of this stuff so my brain hurts Edited April 25, 2007 by CoolMaster Share this post Link to post Share on other sites More sharing options...
CoolMaster Posted April 25, 2007 Posted April 25, 2007 #include <iostream> #include <string> #include <fstream> #include <cstdlib> #include <time.h> using namespace std; const char slash = '_'; const char dot = '.'; const char star = '*'; const int maxrow = 20; const int maxcolumn = 70; void getfromfile(ifstream &infile, int generation[maxrow][maxcolumn], int &initrow, int &initcolumn); double getrand(); void displaygen(int matrix[maxrow][maxcolumn],int initrow, int initcolumn); void generate (int generation[maxrow][maxcolumn], int nextgen[maxrow][maxcolumn], double like,int initrow, int initcolumn); void copygen (int generation[maxrow][maxcolumn], int nextgen[maxrow][maxcolumn], int initrow, int initcolumn); int main() { int generation[20][70]; int nextgen[20][70]; double like; int cycles; int initrow; int initcolumn; int counter = 0; string filename; ifstream infile; cout << "What is the filename? "; cin >> filename; infile.open(filename.c_str()); if(!infile) { cout << "File is corrupt or missing ending program..." << endl; return 1; } if(infile) { cout << endl << "File Opened " << endl; cout << "How many time cycles would you like this program to run?: "; cin >> cycles; cout << "How likely is the virus to spread to a neighbor (0-1)? "; cin >> like; while(like < 0.0 || like > 1.0) { cin.clear(); cout << "Incorrect Range, please enter a range from (0-1): "; cin >> like; } getfromfile(infile, generation, initrow, initcolumn); displaygen(generation, initrow, initcolumn); while(counter < cycles) { copygen (generation, nextgen, initrow, initcolumn); generate(generation, nextgen, like,initrow,initcolumn); displaygen(generation, initrow, initcolumn); copygen (nextgen, generation, initrow, initcolumn); counter++; } } return 0; } double getrand() { srand((unsigned)time(NULL)); //Seed rand func double theRand = (rand() % 10 + 1) / 10.0;//gives a decimal back out return(theRand); } void getfromfile(ifstream &infile, int generation[maxrow][maxcolumn], int &initrow, int &initcolumn) { int rows,columns,a,b; int temp; infile >> initrow; infile >> initcolumn; for(int a = 0;a < initrow; a++) { for(int b = 0;b < initcolumn; b++) { infile >> temp; generation[a][b] = temp; } } } void displaygen(int matrix[maxrow][maxcolumn],int initrow, int initcolumn) { for(int a = 0;a < initrow; a++) { for(int b = 0; b < initcolumn; b++) { if(a == 0 || a == initrow-1) { cout << slash; } if(b == 0 && a != 0 && a != initrow-1) { cout << slash; } if(b == initcolumn-1 && a != 0 && a != initrow-1) { cout << slash; } if (matrix[a][b] == 0 && a != 0 && b != 0 && a != initrow-1 && b != initcolumn-1) { cout << dot; } else if (matrix[a][b] == 1) { cout << star; } } cout << endl; } } void generate (int generation[maxrow][maxcolumn], int nextgen[maxrow][maxcolumn], double like, int initrow, int initcolumn) { //generate your new generation into nextgen based upon generation your initial gen for(int a = 0; a < initrow; a++) { for (int b = 0; b < initcolumn; b++) { if(generation[a][b] == star) { nextgen[a][b] = slash; } } } } void copygen (int generation[maxrow][maxcolumn], int nextgen[maxrow][maxcolumn], int initrow, int initcolumn) { for(int i = 0; i < initrow; i++) { for(int j = 0; j < initcolumn; j++) { nextgen[i][j] = generation[i][j]; } } } Does that look any better? im so sorry im a huge pain in the butt. my brain is just totally out of it. but Im trying to folllow ur steps Share this post Link to post Share on other sites More sharing options...
hardnrg Posted April 25, 2007 Posted April 25, 2007 try putting some debug info... like instead of just displaying generate, display generate AND nextgen every time displaygen(generation, initrow, initcolumn); displaygen(nextgen, initrow, initcolumn); and then you can see what's going on Share this post Link to post Share on other sites More sharing options...
CoolMaster Posted April 25, 2007 Posted April 25, 2007 (edited) Aight will do, since it's not changing I know something's messed up in my generate function, it's just not changing the *'s to _'s after some debugging, when I display nextgen after I do the generate function. it makes everything just dots.....so it's like getting rid of everything? i must be missing something edit: i edited out this line //nextgen[a] = slash; in the generate function and it didnt delete everything......so it must be something with that line, any ideas? why what i have wouldnt work? Edited April 25, 2007 by CoolMaster Share this post Link to post Share on other sites More sharing options...
CoolMaster Posted April 25, 2007 Posted April 25, 2007 (edited) OK well I figured that out, all my arrays were ints and I was looking for a char......yeah Im dumb. so I changed my arrays to char arrays and it is changing the nextgen.....but is giving me some really messed up output What is the filename? gen1.dat File Opened How many time cycles would you like this program to run?: 4 How likely is the virus to spread to a neighbor (0-1)? .5 ______________________________ _...*........................_ _......*....*................_ _...........*................_ _............................_ _...........*................_ _............................_ _...........*................_ _............................_ _............................_ _...........*................_ ______________________________ _________*_____________________ _.........._ _............._ _........_ _........._ _......_ _............._ _.**........****._ _............._ _.............._ _......_ ______________________________ ______________________________ _...*........................_ _......*....*................_ _...........*................_ _............................_ _...........*................_ _............................_ _...........*................_ _............................_ _............................_ _...........*................_ ______________________________ _________*_____________________ _.........._ _............._ _........_ _........._ _......_ _............._ _.**........****._ _............._ _.............._ _......_ ______________________________ ______________________________ _...*........................_ _......*....*................_ _...........*................_ _............................_ _...........*................_ _............................_ _...........*................_ _............................_ _............................_ _...........*................_ ______________________________ _________*_____________________ _.........._ _............._ _........_ _........._ _......_ _............._ _.**........****._ _............._ _.............._ _......_ ______________________________ ______________________________ _...*........................_ _......*....*................_ _...........*................_ _............................_ _...........*................_ _............................_ _...........*................_ _............................_ _............................_ _...........*................_ ______________________________ _________*_____________________ _.........._ _............._ _........_ _........._ _......_ _............._ _.**........****._ _............._ _.............._ _......_ ______________________________ Press any key to continue . . . EDIT: whoops......for the getfile function i forgot to read in the temp as a char. but it just makes the first stuff dissapear Edited April 25, 2007 by CoolMaster Share this post Link to post Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now