Skip to content
View in the app

A better way to browse. Learn more.

Tip.It Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Promise

Members
  • Joined

  • Last visited

Everything posted by Promise

  1. I love you guys so much. I've worked on this code for hours. :wall: :wall: :wall: :wall: All these little details are killing me! Big props to people who do this for a living. :twss:
  2. Changing line 30 to: numlines = readFile (infile, outfile, int&, int&, double&, double&); Gives me error: error C2062: type 'int' unexpected
  3. I got the openfile and readfile mixed up when I was editing the declaration. Please bear with my noob. :mrgreen: Okay, so the openfile is working, and trying to get the readfile to be good. Thank you for all the help<3
  4. Now it saying readfile function does not take 2 arguments....
  5. That fixs the syntax error I was getting about the semi colon. :grin:
  6. Thank you for pointing that out. I missed while changing up that portion of the code. After doing that, I got another error. " 'openFiles' : function does not take 2 arguments" I never got that error till I changed the declaration for readFile. opened = openFiles (infile, outfile); if (!opened) exit (1);
  7. Changing the else if to just else gets rid of the fatal error, but gives me a different error saying "syntax error : missing ';' before '{'" The red font is where the error is coming from. (Also where i changed the else if to just else. int readFile (ifstream& input, ofstream& output, int& countMale, int& countFemale, double& sumMaleGPA, double& sumFemaleGPA) { char first; int line_count = 0; double second; if (input.eof()) return line_count; else { while (input.good()) { input >> first >> second; line_count++; if(first == 'm') { sumMaleGPA += second; countMale++; } [color="#FF0000"]else(first == 'f') {[/color] sumFemaleGPA += second; countFemale++; } } }
  8. Markup..I'm horrible at c++. My mind works to fabricate steel frames, suspension, and machinery. This c++ does not compute well at all with me. :mad: Havent finished the code, but this is what I have so far. Just trying to get it to work before I continue as I am getting a fatal error... :ohnoes: :ohnoes: :ohnoes: #include <fstream> #include <iostream> #include <iomanip> #include <string> #include <cmath> using namespace std; bool openFiles (ifstream&, ofstream&); int readFile (ifstream&, ofstream&); void outLine (int, double, int, ofstream&); int countMale = 0; int countFemale = 0; double sumMaleGPA; double sumFemaleGPA; int main() { int numlines = 0; ifstream infile; ofstream outfile; bool opened; opened = openFiles (infile, outfile); if (!opened) exit (1); numlines = readFile (infile, outfile); cout << "\n" << numlines << "lines read and written.\n"; infile.close(); outfile.close(); return 0; } bool openFiles (ifstream& input, ofstream& output) { string filename; cout << "INPUT file name please: "; cin >> filename; input.open (filename.c_str()); if (input.fail()) { cout << "Input file not found or corrupt!\n"; return false; } 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; } return true; } int readFile (ifstream& input, ofstream& output, int& countMale, int& countFemale, double& sumMaleGPA, double& sumFemaleGPA) { char first; int line_count = 0; double second; if (input.eof()) return line_count; else { while (input.good()) { input >> first >> second; line_count++; if(first == 'm') { sumMaleGPA += second; countMale++; } else if(first == 'f') { sumFemaleGPA += second; countFemale++; } } } double average = 0; for(int i = 0; i < countMale; i++) average += sumMaleGPA; average = average / countMale; return line_count; } void outLine (int f, double s, int c, ofstream& out) { out << setw(3) << c << ' ' << setw(4) << f << ' ' << setw(6) << s << endl; }
  9. AHHH! I did not realize that was supposed to be apart of the same function....editted the code above. Edited it again.... I'm majoring in mechanical engineering...no idea why they made this class mandatory for me. #-o
  10. Only 27 dung. :( ( took a near 2 year breal and returned recently) :mrgreen:
  11. EDIT AGAIN: (AHHHH) This is the current code.... int readFile (ifstream& input, ofstream& output, int& countMale, int& countFemale, double& sumMaleGPA, double& sumFemaleGPA) { char first; int line_count = 0; double second; if (input.eof()) return line_count; else { while (input.good()) { input >> first >> second; line_count++; if(first == 'm') { sumMaleGPA += second; countMale++; } else if(first == 'f') { sumFemaleGPA += second; countFemale++; } } } double average = 0; for(int i = 0; i < countMale; i++) average += sumMaleGPA; average = average / countMale; return line_count; }
  12. I'm down to this, but its not returning a value. :-k int countMale = 0; int countFemale = 0; double sumMaleGPA; double sumFemaleGPA; int readFile (char first, double second, ifstream& input, ofstream& output, int& countMale, int& countFemale, double& sumMaleGPA, double& sumFemaleGPA) { if(first == 'm') { sumMaleGPA += second; countMale++; } else if(first == 'f') { sumFemaleGPA += second; countFemale++; } }
  13. No problem! I liked your explanations and examples anyways! I will post a section of the code when I finish changing it. :thumbsup:
  14. My text requires me to use specific variables. So I had to change what you gave me a little. I was required to use countFemale, countMale, sumFemaleGPA, and sumMaleGPA. So after substituting in what you typed, does this all still look correct? Also, should the function be an int or a void? Its not returning a value for some reason? #-o EDIT: Forgot the last bit of code....sorry haha. :mrgreen: int countMale = 0; int countFemale = 0; double sumMaleGPA[100]; double sumFemaleGPA[100]; int readFile (ifstream& input, ofstream& output, int& countMale, int& countFemale, double sumMaleGPA[], double sumFemaleGPA[]) { char first; double second; if(first == 'm') { sumMaleGPA[countMale] = second; countMale++; } else if(first == 'f') { sumFemaleGPA[countFemale] = second; countFemale++; } }
  15. Visual studios is telling me arrays of references are illegal :wall: For this: int readFile (ifstream& input, ofstream& output, int& m, int& f, double& male[], double& female[])
  16. That makes complete sense to me! :thumbsup: Thank you so much for all your help so far! So on the side, I've been trying to figure out how to get input data from multiple text files...my thinker is telling me to ask the user after the one text file as been input, if he would like to continue, or input another file. Then use an if else statement?
  17. Just to clarify, are we using double for the arrays because of the GPA decimal points or are we using double as a counter for male/female count? Just need to be sure because my teacher turns into the spawn of satan when she grades.... :ohnoes:
  18. EDIT: typed this before I saw your post!!! :mrgreen: So something like this to get me started? I have no idea but making educated guesses...my notes all use while loops so I think I need to use loops? :?: void initializeArrays (char m[], char f[]); { int i = 0; char gender; while (gender =='m' || gender == 'f') } and then there is where I am stumpped. How Do i put the data from the text file into that??
  19. I am a noob at this, but how exatly do I put data from the text file into an array? :mellow: Going over notes now...
  20. Yay! Just that one small change got my program to read all 20 lines instead of just 1. This is the output file: [hide=output] 1 109 3.1 2 109 2.63 3 109 3.5 4 109 3.55 5 109 3.47 6 102 3.98 7 109 3.33 8 109 2.54 9 102 3.35 10 109 1.8 11 109 2.81 12 102 3.34 13 102 3.45 14 109 3.84 15 109 3.4 16 109 2.57 17 102 2.45 18 102 2.71 19 102 3.75 20 102 3.9 [/hide] So now that my program can rread all the lines, I need to sort the gender. Its required I make a separate function for this. Honestly don't even know where to start with this. Loop? If/else statements? ughhhhh :wall:
  21. It should be like this, correct? Made the change in red. int readFile (ifstream& input, ofstream& output) { [color="#FF0000"]char[/color] first, line_count = 0; double second; if (input.eof()) return line_count; else { while (input.good()) { input >> first >> second; line_count++; outLine (first, second, line_count, output); } } return line_count; }
  22. We just learned arrays yesterday so this is all pretty knew to me. Ahhh, so instead of using bool, i need to use char? EDIT: just re-read what you wrote. Nvm about the bool! :mrgreen:
  23. Having a really hard time with this program. And thought I could get some help here...Thanks for any help in advanced! The assignment is to write a code that will open 2 text files full of male and female GPAs. This is an example of the text file. m = male, and f = female. [hide=exmaple] m 3.1 m 2.63 m 3.5 m 3.55 m 3.47 f 3.98 m 3.33 m 2.54 f 3.35 m 1.8 m 2.81 f 3.34 f 3.45 m 3.84 m 3.4 m 2.57 f 2.45 f 2.71 f 3.75 f 3.9 [/hide] My program must be able to output the average of males and females into a seperate text file. So far I am able to get the file and open one. I'm stumped on how to get the info from the file, and get the average. This is what I have so far... #include <fstream> #include <iostream> #include <iomanip> #include <string> #include <cmath> using namespace std; bool openFiles (ifstream&, ofstream&); int readFile (ifstream&, ofstream&); void outLine (int, double, int, ofstream&); int main() { int numlines = 0; ifstream infile; ofstream outfile; bool opened; opened = openFiles (infile, outfile); if (!opened) exit (1); numlines = readFile (infile, outfile); cout << "\n" << numlines << "lines read and written.\n"; infile.close(); outfile.close(); return 0; } bool openFiles (ifstream& input, ofstream& output) { string filename; cout << "INPUT file name please: "; cin >> filename; input.open (filename.c_str()); if (input.fail()) { cout << "Input file not found or corrupt!\n"; return false; } 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; } return true; } int readFile (ifstream& input, ofstream& output) { int first, line_count = 0; double second; if (input.eof()) return line_count; else { while (input.good()) { input >> first >> second; line_count++; outLine (first, second, line_count, output); } } return line_count; } void outLine (int f, double s, int c, ofstream& out) { out << setw(3) << c << ' ' << setw(4) << f << ' ' << setw(6) << s << endl; }
  24. Where and what would be the best place/monster to train with them? Thank you in advanced :mrgreen:
  25. I really like this....can't wait to see more! :thumbsup:

Important Information

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.