Jump to content

Tecmaster

Members
  • Posts

    1604
  • Joined

  • Last visited

Everything posted by Tecmaster

  1. Sorry about that, I got sidetracked with some other work. It seems like there's some routing issues going on at the moment. I'll poke our technical admin this way and see if he can sort things out with the host. :) Just keep trying and we'll have things back to normal soon.
  2. If you are running windows, open up the command prompt and type the following. ping tip.it /n 5 Let me know what it comes back with.
  3. Are you referring to the Tip.It homepage or the RuneScape homepage?
  4. Our Monster Hunting Guides Expert, Warriormonkx, is currently in the process of renovating all of our monster hunting guides. However this is a very time consuming process so it will be a little while before any more are ready to be released. Keep watching though as they are being worked on. :)
  5. You'll want to get rid of the outfile load in the loadFiles function, the one in write data is the one we're using to write the output. This code in the readFile function is also completely superfluous and can be removed: double average = 0; for(int i = 0; i < countMale; i++) average += sumMaleGPA; average = average / countMale; As for the outputs being wrong, try throwing in a cout statement on the averageMaleGrade and averageFemaleGrade variables after all of the output << statements. This will dump them to the console so that you can see if they are correct or not. If they're not try backtracking around the program with those cout statements to see where they're not being set properly. Unfortunately I do have to go to bed now, but I'll check back in the morning. :)
  6. averageGrade(countMale, sumMaleGPA); averageGrade(countFemale, sumFemaleGPA); This call should be after the call to readFile() and should be filling the variables averageMaleGrade and averageFemaleGrade respectively like this: averageMaleGrade = averageGrade(countMale, sumMaleGPA); averageFemaleGrade = averageGrade(countFemale, sumFemaleGPA); There's no point calculating the averages if we don't have any data yet. :P As for outputing to a file, once you have the averages calculated you need to write a quick function to write the output to a file. To help with reading from multiple files later we'll move the code to open the output file into this new function as well. bool writeData(int countMale, int countFemale, double averageMaleGrade, double averageFemaleGrade) { ofstream output; cout << "OUTPUT file name please: "; cin >> filename; output.open(filename.c_str()); if (output.fail()) { cout << "Output file: deevice not found or disk full!\n"; return false; } output << "Number of Males: " << countMale << endl; output << "Average Male GPA: " << setprecision(3) << averageMaleGrade << endl << endl; output << "Number of Females: " << countFemale << endl; output << "Average Female GPA: " << setprecision(3) << averageFemaleGrade; output.close(); return true; } Because we're now opening and closing the output file in this function we can now remove all the other code related to the outfile in main and the openFiles function. This also means that you can now close infile in main after you read the file but before calculating the averages and then call openFiles, readFile again to read from a second file, then calculate the averages.
  7. You already have the output file pointer that you connected to the output file in the openFiles function, so all you have to do is create a new function and pass in that outfile variable as well as the averages and all you have to do in that function is outfile << "Write your stuff here";
  8. In that case you can just create a function called calcAverage() which takes in one of the counters and one of the totals and returns the average. Then in main you can just do something like: double maleAvg = calcAverage(countMale, sumMaleGPA); double femaleAvg = calcAverage(countFemale, sumFemaleGPA);
  9. You're getting there! You still need to calculate the averages in the main() function and then write them to the file. double average = 0; for(int i = 0; i < countMale; i++) average += sumMaleGPA; average = average / countMale; return line_count; You should move this block of code to the main() function after you read the contents of the file. Then do it again with a different 'average' variable name to calculate the male and female averages. From there you can write it to the file with a simple outfile << "Write stuff here";
  10. Edit: Dudecrush beat me to it. :P Don't change it to an else, keep it an else if. The only reason that it's stopping the fatal error is because that error is being caught before the fatal one. The fatal error is in the fact that your function prototypes (at the top of the program), don't actually match the functions you have. For example int readFile (ifstream&, ofstream&); doesn't match the readFile function. Make sure you update them whenever you change the parameter list for the function.
  11. One more tip, make sure you're calculating the averages in main() and not the readFile function. ;)
  12. char first; int line_count = 0; double second; if (input.eof()) return line_count; else { while (input.good()) { input >> first >> second; line_count++; //The if/else if block should go here } } return line_count; Don't forget about the rest of the 'stuff' that was in the function before, you still need to read in the data from the file to populate those first and second variables and keep counting the lines. The while loop is also what keeps the system going until you reach the end of the file. Edit: you also don't need to be passing the first/second variables into the function, they should be declared locally.
  13. Ok, I was just thinking about this a little bit more and realized that you don't actually need to use the individual data for anything, only the average. So, instead of making it an array, just make sumMaleGPA and sumFemaleGPA regular doubles and add the value of the current line to them. I.E. if(first == 'm') { sumMaleGPA += second; countMale++; } (You do need to add the & sign back after the word double now because they're no longer arrays) Because you only need the average of each of the GPA's you can just keep a running sum of the male GPA's and the female GPA's and then just divide them by the count at the end. Once you finish reading in the data you'll be left with sumMaleGPA and sumFemaleGPA which contain the total of all of the male and female GPA's and the countMale and countFemale variables which then contain the number of males and females. You can then just divide to get the averages and write to the file. Sorry for misleading you there with the arrays for a while, I was reading into the problem a bit too far and thought you had to do other processing down the line that you didn't.
  14. Oh right, fail. I forgot that arrays are automatically passed by reference when you pass them into functions, so you don't need the & sign after the word double. My bad. int readFile (ifstream& input, ofstream& output, int& m, int& f, double male[], double female[])
  15. No problem! The way we've set things up, as long as you're passing the 4 variables from main into the readFile function, you can simply call openFile and readFile again to read from a second file. The only difference is that you have to change your code to calculate the average and write to the output file later in the program after you're done reading from all the files you want to.
  16. Eek! Anywho, the doubles are for the two arrays that hold the gpa values because they are decimals. The 'm' and 'f' variables are ints and are simply counters that keep track of how many males and females we've processed so far. They're also used in calculating the averages later on because they contain the total number of males and females once you finish reading in the data.
  17. What you'll want to do is to create 4 variables in main, and then pass them as parameters into the readFile() function. For example int m = 0, f = 0; // Male and female counters double male[100], female[100]; //Male and female arrays Then for your function: int readFile (ifstream& input, ofstream& output, int& m, int& f, double& male[], double& female[]) In the function you can then do something like this instead of writing to the outfile. //read file here if(first == 'm') { male[m] = second; m++; } else if(first == 'f') { female[f] = second; f++; } As long as you don't have more than 100 males or females this will result in two arrays back in main that contain the averages of the males and females respectively. Then you can simply loop through the two arrays as needed to tally up the averages like so: double average = 0; for(int i = 0; i < m; i++) average += male[i]; average = average / m;
  18. Hey, no problem I'm here to help out. My suggestion is that you create two arrays of 100 items each. (assuming you're program won't be processing more than 100 males or females) Then, you can use if/else if/else statements to determine which gender (your 'first' variable) the person is and add them to the appropriate list. You can use two separate counters (m and f) to keep track of how many males and females you have. There are better ways to do it, but until you learn about dynamic memory or vectors this is probably the easiest way.
  19. As for processing the averages, rather than immediately outputting the data to a new file, what you need to do is to dump all of the incoming data into two lists (or dynamic arrays), one for male and one for female. On each line you read in you should be able to use the first variable to determine if the gender is female or male, and then add the second value to the correct list. From there, once you've read in both files you can loop through both lists to calculate the two averages and then write them to the output file. Hopefully I didn't confuse you too much. :P
  20. Your variable "first" should be of the 'char' datatype, not int as you're reading in a alphabetic character rather than a number for the gender. Once you fix that the program will be able to read in the data and output it to the file. I'll get back to you on the averages in a moment.
  21. This has now been done. :) Thanks for the suggestion!
  22. There are a large number of wolves available on white wolf mountain if you want to get the task over with quickly. You can also kill the big wolf there whenever it spawns for a bit more XP as well.
  23. I'm actually quite surprised that we didn't do this already, I'll talk to the crew and see what they think.
  24. This has actually been on my list for a while but I never got around to actually doing it. :P At this point we probably won't be implementing these for the current site design as it's not going to be around long enough to be really used a lot, but I'll look into implementing them in the new site design.
  25. Yes, you can do this by clicking the 'Find my content' button on the person's profile page. This brings up a list of all the threads they've posted on recently. I'm also going to lock this as you have your answer and this is more of a forum issue than a website issue. If you need more help feel free to post more questions in the Help and Advice forum. :)
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.