2,045 Posted Topics
Re: You're passing a char into your DrawBar() function which is incorrect. Keep a separate int counter to keep track of your guesses and then give that to Drawbar after a guess. You'll never be entering in the characters '1' '2' '3' '4' '5' as part of your alphabet guesses so … | |
Re: Take in 2 doubles from the user and then use your constructor to create a new object. [code] double r,im; cin >> r >> im; complex num(r,im); [/code] | |
Re: int findMax(int [][20]) needs to be [icode] int findMax(int grade[][20]) [/icode] Definitions always need the identifier, declarations do not. There's no identifier there so the compiler reflects a mismatched brace somewhere even though there isn't. | |
Re: See [url]http://www.nrbook.com/a/bookcpdf.php[/url] section 9.4 (you need some stupid plug-in in addition to Acrobat Reader but if you're in this line of inquiry this book is gospel). It does not provide a clean answer to this but does have a calculation for how much the error changes at each step. It's … | |
Re: I think your || should be && cause 89 is greater than 60 so it short circuits and you get anything over 60 as a D. | |
Re: [code] int GeneticAlgorithm::BinarySelection(int populationSize) { firstRandom = static_cast<int>(( static_cast<double>(rand()))/ static_cast<double>( RAND_MAX) *(populationSize-0 + 1) + 0); secondRandom = static_cast<int>(( static_cast<double>(rand()))/ static_cast<double>( RAND_MAX) *(populationSize-0 + 1) + 0); } [/code] You're trying to use a value returned by this method in a later calculation [icode] GeneticAlgorithm::Optimize()[/icode], but BinarySelection returns nothing (I … | |
Re: Try it as: [icode]cout.setf(ios::fixed); cout << setprecision(1) << "Mean: "; [/icode] Instead of: [icode] cout << fixed << setprecision(1) << "Mean: "; [/icode] | |
Re: Construct a string with [icode]string s; s = "C:\\Program Files\\Java\\jdk1.6.0_"+num; [/icode]. Then if (Directory.Exists(s)) is true, then output the substring of s that has "jdk"+ a string with "version" + the other stubstring "1.6.0_1". | |
Re: Have you learned while loops? Then you could use while(inFile >> student[count]) and increment count in the body of the loop. That way you'll be able to use that count in a subsequent for loop to display your array rather than displaying empty portions at the end. If you haven't … | |
Re: If you are using a for loop to print your stars, why not have another for loop to print spaces? So run one for loop to loop over the # of lines you need and within that have 2 for loops (stars and spaces). Hand code it to convince yourself … | |
Re: Declare [icode] Node<L>* ptr; [/icode] inside your method but outside the else block. Then inside of else set [icode] *ptr = first; [/icode] You might need to change what you return but I'm not absolutely sure. | |
Re: The first problem is with your constructor, you have it as taking in a string but in the constructor definition you don't give the string a name nor assign it to anything within that constructor. Also, [code] string dayType::printDay(){ cout << (weekDay + (currentDay-1)); } string dayType::prevDay(){ cout << (weekDay … | |
Re: Make a variable: double maxtemp = 0; (so that you're ensured it will be lower than any of your values). As you are going through your for loop t `if celdeg[k] >=maxtemp, set maxtemp = celdeg[k]`. If you need to keep track of where that occurs in your array, simply … | |
Re: Don't use the getline methods, just redirect from the stream as you would for any of the other variables (e.g, [icode] savedGame >> weaponName;[/icode] and same for armorName). If you are writing the files manually it's finicky about the booleans (requiring 0 or 1 representation, I think I didn't explore … | |
Re: Here's a brief skeleton that you can work from. It seems like your instructor wants you to break off the methods (no functions in C#). There's an example do while loop along the lines. Flip ahead in your text to learn more about methods or do a quick net search. … | |
Re: At least post the section of the code you are having trouble with. People like to keep stuff in the forum so everyone can learn (among other reasons). | |
Re: Something like this? I can't tell without knowing what your functions are doing: [code] for (int i = 0;i<mystring.length();i++) { for(int j=0;j<i;j++) cout <<" "; cout<<mystring.substr(mystring.length()-1-i,1)<<endl; } [/code] | |
Re: why don't you create a struct called menuitem that can store the description/price/etc of one item. Then make an array of all the menu items selected for the order. You could call up the menuitem with a unique key (1,2,3,4...} stored within the struct menuitem. | |
Re: I was going to suggest using a flag in this if statement as to whether or not you'd found the character included, but I don't know if that's the best practice [icode] if (bokstav != gjettet_bokstaver[array_size]) [/icode]. Just rereading it now, do you mean for array_size in the second if … | |
Re: I was able to run the following code on my machine. Word* has the same size as char *. I don't know if maybe I'm missing something or if the conditions are different (I'm using gcc 3.4.2 in Vista64). [code] #include<iostream> #include <vector> using std::cout; using std::endl; using std::vector; int … | |
Re: Calculating commission at the beginning like that will just calculate it once, and with the wrong amount for the sale. Firstly, turn the whole thing into a do while loop because you have a while at both ends and that doesn't make sense. Then make commissionA, commissionB and commissionE variables. … | |
Re: [Quote] The book directs us to include global arrays that will hold this information and than pass them as arguments into the bookInfo function.. [/QUOTE] Getting you into the really bad habits early, eh? I don't fault you in any way for the text that the instructor chose, but what … | |
Re: [icode] typedef struct teams; [/icode] should be [icode] typedef struct TeamInfo teams; [/icode] Change your cout on line 67 above to cout <<variable1<<"\t\t"<<variable2<<"\t\t" etc. etc. There are major issues with scope too but grab the basic stuff first. | |
Re: I think the bottom line is that you need some kind of "base case" for your recursion. See this page: [url]http://www.java-tips.org/java-se-tips/java.lang/finding-greatest-common-divisor-recursively.html[/url] (the language is Java, but the concept is identical) [code] if (b==0) return a; else return gcd(b, a % b); [/code] The b==0 is their base case, like f(0) … | |
Re: You have declared three different constructors for Barcode: [icode]Barcode(int zipcode); Barcode(char bar); and Barcode() [/icode] If you declare any other constructors and then a default one, you must define that default constructor (in fact in your file you don't have _any_ of them defined). | |
Re: [icode] tally[i+2] != tally[i] || tally[i+1] [/icode] (line 34) is not doing what you want it to do. You need [icode] (tally[i+2] !=tally[i]) || (tally[i+2] !=tally[i+1]) [/icode]. | |
Re: check the first field to see if it is +,-,or a number. if it's a sign or a number, take in the next number etc. until you reach / (so in your mixed number example you invalidate the input based on the space). read your numbers into a string but … | |
Re: Make the div element of your structure of type double. Then cast one (or both of numOne and numTwo to double before performing the calculation. [icode] struct calcType {int add; int sub; int mult; double div; int mod;};[/icode] [icode]myCalc.div = (double)numOne/(double)numTwo; [/icode] | |
Re: in a class (or struct) where c is a pointer to said class and member is a public method of c (can be a public field also) c->member() is the same as (*c).member() | |
Re: This looks like it only works on Windows server but a search of "GPMC Windows XP" does bring up some hits. [url]http://technet.microsoft.com/en-us/windowsserver/grouppolicy/default.aspx[/url] | |
Re: Except you need to move the average calculation outside the for loop so it's not done each time. You should cast total to a double before the division so that your average isn't truncated. | |
Re: Why are you calling resultsfn with only 5 parameters when it takes 11 in your prototype and definition? It will not assume defaults for those. Often what the compiler says, goes. | |
Re: You should probably use [icode] srand(time(0)); [/icode] at the top ([url]http://www.cplusplus.com/reference/clibrary/cstdlib/rand/)and[/url] do your subsequent calls to rand() % dimension (not rand %100 as a 3 by 3 is not going to need numbers up to 99). As it is your program is trapped on one value and it keeps looping … | |
Re: Something weird is going on with your streams they are getting lumped together if your queue starts out empty [code] Printing pre-reverse U From the print step ------------------------- Printing reversed U (R) From the print step ------------------------- Printing pre-reverse U From the print step racecar ------------------------- Printing reversed U (R) … | |
Re: That's the purpose of the assert, to halt the program if a particular condition is not met. So you're calling your [icode] front() [/icode] or [icode] back() [/icode] methods on what apparently is an empty queue. | |
Re: I won't pretend to be an expert but I'm nearly 100% that you can just write a normal for loop and get the exact same results, but it completely depends on your compiler and system. [url]http://books.google.com/books?id=mM58oD4LATUC&pg=PA228&lpg=PA228&dq=register+keyword+C&source=bl&ots=rn-80oICcn&sig=siWxPD99jsGYpXrKp8ZszMJhSec&hl=en&ei=T7T5Sv78KIecML6OsNwK&sa=X&oi=book_result&ct=result&resnum=9&ved=0CB4Q6AEwCDgK#v=onepage&q=register%20keyword%20C&f=false[/url] Also see: [url]http://www.daniweb.com/forums/thread19956.html[/url] (post #17) | |
Re: Maybe I'm missing something, but do you actually create myIntList (instantiate your List object) before you attempt to use it in main()? | |
Re: should be [icode] if(pkg == 'A' || pkg=='B' || pkg == 'C') [/icode] otherwise they won't match character for character. Your switch statement should look like: [code] switch(pkg) { case 'A': //case A goes here break; case 'B' : // case B goes here break; etc. } [/code] | |
Re: Before the cubing step values[] = original value squared, so saying cubed = values[]*values[] = originalvalue squared * original value squared = original value to the fourth. Also in your parlance, cube_root is the same as cubed which it is not (e.g., cube root of 27 = 3). So, ultimately … | |
Re: [quote]Then it gives you the option to send an error report or dont send. How do I get that to go away? [/quote] Write a program that doesn't overstep your name array and crash. Only giving you a hard time... There isn't a next element to test after "Tim." | |
Re: See [url]http://www.cplusplus.com/reference/iostream/manipulators/setw/[/url] That way the widths of your fields will be constant and you can use your ostream directly without all that mildly stressful string manipulation. | |
Re: You still have the endl (s) in your code. You need to get rid of those otherwise you will be printing out stars and spaces with a carriage return line feed after them. Here's a hint - on the way down you're subtracting one space, once you get to the … | |
Re: Also see my post in your other thread about the flaw in your multiplication... Stu, I'm thinking having 2 functions (one operator and one non-operator) might have been part of the assignment. | |
Re: Seem to be missing semicolons after your class declarations in the headers: [code] class Feature { private: int Id; int Frequency; string Description; public: void setId(int i); void setFrequency(int f); void setDescription(const string d); int getId(); int getFrequency(); string getDescription(); Feature(int i, int f, const string d); }; <-------------- (and … | |
Re: Your multiplication and division functions are incorrect. A/B * C/D is simply (A*C) /(B*D) you have some extra factors in there. Your numerator for the division function is actually the correct amount, so just separate that into the numerator and denominator. Scratch some examples out on paper to convince yourself. … | |
Re: EDIT: missed how it was before. But your Node itself has a default constructor taking no arguments. I think the problem lies in all the private inner class friend layout that you have. I understand that you may have a requirement for data hiding but I can't quite wrap my … | |
Re: [icode] cin << info; [/icode] is incorrect, the [icode] >> [/icode] operator should be used instead. Probably just glazed over it because you had it right the other times. | |
Re: Don't use the endl as that's moving each * onto it's own line. You have the right idea with 2 for loops. Are you prevented from adding a third to step through each line of the diamond? You might use some if statements, placed strategically to decide which of the … | |
Re: Why can't myName() return a string instead of an int? Also, the restriction on cout seems to be for your function body only. Great post title, BTW. | |
Re: Check out: [url]http://www.parashift.com/c++-faq-lite/templates.html#faq-35.13[/url] It's touchy about template parameters being defined in separate compilation units. It probably has to do with your DataType parameter being used in a function with your T parameter in main. I did not try your code so I'm not positive. P.S. What's up with that font? … |
The End.