2,045 Posted Topics
Re: Extra semicolon on line 17: [icode] if(At_Bat >= Hit); [/icode] | |
Re: In main() you don't need the void in front of displayBoard() like you do in the prototype up above. Is there no definition for the displayBoard() either? It doesn't seem like you have quite enough to be running it yet. It might compile but that's just a step in the … | |
Re: Asking for the sake of curiosity, is there a specific reason you're not using the filestreams and <string>? for example see [URL="http://www.cplusplus.com/reference/string/getline/"]this[/URL] which might (I don't know for sure) have similar insides and can definitely be used in a loop. | |
Re: You don't need it: [code] int i = 0; while(input>>employee[i].spotnumber) { input >> employee[i].driver_name; input >> employee[i].car_reg; i++; } [/code] Search the threads on this site about eof and why it's not reliable. E.g., [url]http://www.daniweb.com/forums/thread19956.html[/url] , post #18 on that thread. (that thread/article is also the 5th sticky post down … | |
Re: [QUOTE=rzhaley;1079417] ps my code for some reason keeps shutting down my computer as well. [/quote] Wow that's not supposed to happen. I'd look to other causes unless you mean that your VC# crashes and takes down your PC. To give you a good clue, here is the proper way to … | |
Re: You need downcasting(downcast your base class pointer to a pointer to your derived class -- go "down" the class hierarchy). See [URL="http://www.cplusplus.com/forum/beginner/13300/"]this[/URL] for a good example (aside from the initial post). | |
Re: Do you really want an array to represent the year and the running time? so leave those as ints. Also, any title over 1 word gets truncated. Why not use a getline for that as well? | |
Re: You don't need the () when using a default constructor nor do you need them on the object when invoking a method (you do need them on the method call itself) [code=c++] complex().setRepairPtr(file().getRapairPtr()); should be complex.setRepairPtr(file.getRapairPtr()); and your object declaration should be Complex complex; [/code] The second part of your … | |
Re: Wow, more power to you for taking up C++ in only [I]4 days[/I]. I realize this might not be homework for you but it might make us feel better either way if you took a shot at it yourself first. Even a blend of pseudocode (the beginnings of which you … | |
Re: What is the output you are getting currently? There are a couple of options for a function, one is you can pass in Age[] and I e.g., [code] float average(int agearr[],int count) { float ave int sum (over all agearr) cast sum to a float ave = sum divide by … | |
Re: There's a mismatch on your signatures [code=c++] ShowAll(x, y, z, average, max, min); vs. void ShowAll(int x, int y, int z, float average, int min, int max) [/code] | |
Re: [I]Turbo C++[/I] is your problem. There's a lot of nonstandard stuff in your program, like stdlib.h is #include <cstdlib>, and your randomize and random functions are non-standard. You also need to qualify all your library function calls (cout, ifstream,ostream, etc) with std:: or have [icode] using namespace std; [/icode] (but … | |
Re: You need a } right after line 31 in the above code to close off the first for loop. Then they should all balance out. Also, unrelated to this: [code] for ( int i = 0 ; i<I; i++ ) { cout << "Age of Personnel" << ( i + … | |
Re: Hi, welcome. What code do you have so far? You should read [URL="http://www.daniweb.com/forums/announcement8-2.html"]this[/URL]. | |
Re: See [url]http://www.cplusplus.com/reference/iostream/istream/get/[/url] you'll want the third one down that takes a streamsize (there's an example at the bottom of the page but its got some error checking that you can probably put on hold for the time being). As far as the two names in one field is concerned -- … | |
Re: [code] if (plainLine[i] == '\n') cipherLine[i] = '\n'; [/code] If your getline method is separating based on \n anyway, would you need this statement at all? I think you're doing the right thing in reinserting \n in the ofstream | |
Re: Start out with the class declaration. You have a portion of it already written in this post. [code=c++] class StringSet { private: //Probably want your array here public: //Constructor(s) //Your other functions }; //this might go in a header file if you want to Then Stringset::Stringset(String[] mystring) { constructor "stuff" … | |
Re: [quote] I'm not sure because I don't have a main() to test with. [/quote] You could just make a few objects that are equal and not equal to test out your operators e.g. [code] Date today(12,14,2009); Date tomorrow(12,15,2009); Date copyofdate(12,14,2009); cout <<"today < tomorrow "<< (today < tomorrow)<<endl; cout << … | |
Re: Do you have it set up as a Win32 console application or did you choose Win32 project? | |
Re: I think your output and stuff was closer the first time. As of now your write statements aren't really doing anything (I can't even get them to compile like that and they have the wrong # of arguments). To be honest, I find it much easier to use ifstream and … | |
Re: Are you having trouble with the calculation or the output? You already have the row and column totals, just divide by the total number (you'll have to cast the numerator (or both numerator and denominator) to double -- like [icode] rowaverage[i]=((double)rowtotal[i])/7; [/icode] For the output it will be just like … | |
Re: I interpreted your assignment slightly differently: [code] int populateArray(int a[] ) { int numberOfElementsToStore = (int)( 10 + 25 * ((double) rand( ) / (double) RAND_MAX )) ; int i = 0 ; for (int i = 0; i < numberOfElementsToStore; i++) { a[i] = rand() % 100; } return … | |
Re: See the move() method in this [URL="http://pdcurses.sourceforge.net/"]library[/URL]. I've never used it but it claims to work with console based windows apps. You may need to dig around a bit to figure out how to use the dll with your programs. I think something like this is the closest you are … | |
Re: Please see this: [url]http://www.daniweb.com/forums/announcement8-2.html[/url] We'd be glad to help you with your assignment but you must bring at least some code to the table with specific questions. | |
Re: Change student_number to an array of char. Employ the transformation `first = (int)(student_number[0]-'0');` to get the first character back to a digit (you don't need to declare first as first[0] as an array with zero elements is just a regular variable). You'll need to change your scanf also to reflect … | |
Re: [quote] How in the world am I supposed to "get" the first fraction to multiply it with the second one??? [/quote] You have it. Read up in your text about the *this pointer. You've formed this object and now it has a reference to itself: this->numerator and this->denominator are the … | |
Re: I think some small changes are all you need. [code] if (scores[pos]== -1) { count=1; //you could make this a "break;" statement to get you out of the loop (move it after the next statement, though, then take out your second condition in the while loop) //scores[pos]= scores[pos-1]; here was … | |
Re: You commented out your semicolon on that line. Also, I'm not sure if your file was truncated but you don't have a closing brace for main(). EDIT: Also your inner for loop is going to end before your outer one finishes calculating the average. Move that final calculation Average = … | |
Re: I was able to get it work as you have it with this output: [code] Before 1 2 3 4 After 3 4 1 2 [/code] I hate to ask, but we all get these moments, were you trying to swap rows 1 and 2? | |
Re: I believe (I had to try a little example) that it's float* [code] float a[2] = {4.0,5.7}; float b[2] = {1.3,9.8}; string label1 = "label1"; string label2 = "label2"; map<string, float *> mymap; mymap[label1] = a; mymap[label2] = b; cout <<mymap[label1][1]<<endl; [/code] output is 5.7 | |
Re: Please read the following: [url]http://www.daniweb.com/forums/announcement8-2.html[/url] ...but we do want to help :) we just need to see that you've put in some effort. | |
Re: Are you limited to using arrays or can you use vectors? You could use (brace for impact) vector<vector<vector<int> > > | |
Re: Sorry to interject as you are focused on the other functions, but how come you prompt the user for input and then overwrite the values in InitializeArray? (I'm probably missing something obvious...) | |
Re: Could you do something based on the current time? See: [url]http://www.cplusplus.com/reference/clibrary/ctime/time/[/url] If you had two subsequent runs it would be very unlikely that they got the exact same ID. | |
Re: It's [URL="http://www.cs.nccu.edu/~gmilledge/comp1520/comp1520Spring2007/Homework/babynames2004.txt"]here[/URL]: (I helped him on the other post -- mcap, I think you got the abbreviated URL when you cut and pasted) [quote]I think you should use std::list, and no pointers if it's not neccessary! [/quote] We can probably do some "duck typing" (go against the C++ grain for … | |
Re: If your options are numbers (less than 10), why not make it a char variable? If you needed the int value you could just subtract '0' from it. [code] char a = '1'; int b = (int)(a-'0'); [/code] | |
Re: Check out this article. It has the pseudocode right in the first paragraph. Try to convert this into code and post back once you have some specific questions. [url]http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes[/url] | |
Re: C++ Primer Plus is a great text, I have an old ("well loved") 1998 copy still kicking around and while it doesn't have the latest features of the language it's published after ISO so it's got the standard flavor and what I think are a lot of solid examples. Check … | |
Re: Is [URL="http://msdn.microsoft.com/en-us/library/ms379564(VS.80).aspx"]this[/URL] along the lines of what you are looking for? If so there are tons of resources about generics out there. | |
Re: Are you talking about [URL="http://msdn.microsoft.com/en-us/library/5dxy4b7b(VS.80).aspx"]Unions[/URL]? They can still be used in C++ but they can still only hold one item at a time, of a predefined set of types. | |
Re: Put some `//code goes here` tags around your source. Also, you can add to your old post you didn't have to start a new one. Are you allowed to use an array for this? That's probably the easiest way. Create a temporary variable to hold the high and one to … | |
Re: X->membervariable is a shortcut for (*X).membervariable (so it can access a member of a class or struct to which you have a pointer. See [URL="http://www.learncpp.com/cpp-tutorial/87-the-hidden-this-pointer/"]"this" (no pun intended)[/URL] for an explanation of that particular case you cited. [URL="http://www.cplusplus.com/reference/algorithm/"]Here[/URL]'s a good reference for the vector algorithms (it has miniprograms with each … | |
Re: I retooled your method a little bit: [code] void add_names() { //name *temp, *temp2; //temp = new name; name * prior = new name;// * temp; int ranking; int i=0; string male_name, female_name; ifstream in_stream("babynames2004.txt"); //in_stream.open; //opens and loads names & ranks from file if (in_stream.fail()) { cout << "File … | |
Re: You have the bit for displaying the seats right in the code, right in the for loop, it's just that you didn't assign them when the user entered them. You also didn't check the array to make sure that seat wasn't already assigned. Your seats array should have 5 as … | |
Re: I think he meant this link [url]http://www.daniweb.com/forums/announcement8-2.html[/url] though that one fits with his sense of humor... | |
Re: I don't know if this first part has anything to do with it, but were you writing your strings in another program, because the quotation marks on line 50 and the apostrophe on line 55 are the "curly" ones used by word processors and are interpreted differently by the compiler … | |
Re: I got this with a shift of 3: [code] Xqiolqfklqj#rq#d#fulwlfdo#iluvw#whvw/#Vhqdwh#Ghprfudwv#forvhg#udqnv#Wkxuvgd|#ehklqg#'793#eloolrq#lq#srolwlfdoo|#ulvn|#Phglfduh#fxwv#dw#wkh#khduw#ri#khdowk#fduh#ohjlvodwlrq/#wkzduwlqj#d#Uhsxeolfdq#dwwhpsw#wr#grrp#Suhvlghqw#Edudfn#Redpd*v#vzhhslqj#ryhukdxo1 Wkh#elg#e|#wkh#eloo*v#fulwlfv#wr#uhyhuvh#fxwv#wr#wkh#srsxodu#Phglfduh#surjudp#idlohg#rq#d#yrwh#ri#8;075/#gudzlqj#wkh#vxssruw#ri#wzr#Ghprfudwlf#ghihfwruv1#Dssurydo#zrxog#kdyh#vwulsshg#rxw#prqh|#qhhghg#wr#sd|#iru#h{sdqglqj#fryhudjh#wr#whqv#ri#ploolrqv#ri#xqlqvxuhg#Dphulfdqv1 Wkh#eurdghu#ohjlvodwlrq#dlpv#wr#h{whqg#khdowk#fryhudjh#wr#64#ploolrq#zkr#qrz#odfn#lw/#zkloh#eduulqj#lqvxudqfh#lqgxvwu|#sudfwlfhv#vxfk#dv#ghq|lqj#fryhudjh#rq#wkh#edvlv#ri#suh0h{lvwlqj#phglfdo#frqglwlrqv1#Wkrxjk#wkh#ryhukdxo#lv#hvwlpdwhg#wr#frvw#derxw#'4#wuloolrq#ryhu#d#ghfdgh/#wkh#Frqjuhvvlrqdo#Exgjhw#Riilfh#kdv#vdlg#lw#zrxog#fxw#ihghudo#ghilflwv#e|#'463#eloolrq#ryhu#wkdw#shulrg/#dqg#suredeo|#uhgxfh#wkhp#ixuwkhu#lq#wkh#43#|hduv#eh|rqg#wkdw1 [/code] And this with the decrypt: [code] Unflinching on a critical first test, Senate Democrats closed ranks Thursday behind $460 billion in politically risky Medicare cuts at the heart of health care legislation, thwarting a Republican attempt to … | |
Re: Did you go through all of the [code] qmake -project (regardless of your project name) qmake projname.pro (your projects C++ file name+.pro) make [/code] steps. If not, try that. If you have done it, try dividing it up into the three files to see what happens. Qt works with a … | |
Re: [code] for(int i=0; i<count; i++) { if (highest<num[i]) highest=num[i]; highestindex = i; } [/code] But remember you may need to add 1 to highestindex before you output it since your text file probably starts with 1. rather than 0. | |
Re: This part of your code is confusing to me [code] fstream* file = new fstream("GameDetails.txt", fstream::out); ofstream out; out.open("GameDetails.txt",ios::ate); while ( more ) { game.Tic_Tac_Toe_Board(); player = game.Pick_Player(); fstream* file = new fstream("GameDetails", fstream::in); *file << left << setw(30) << setw(25) << "Player" << setw(25) << "Wins" << setw(10) << … |
The End.