2,827 Posted Topics
Re: I know of no "out word" in C or C++. I don't know if that is pseudocode, but if it isn't, it's a syntax error in either language. If "out" refers to "cout" or "output" or "standard out", well, I'm not going to try to guess what you mean. Please … | |
Re: Line 155 isn't going to catch the problem. Try changing line 155... [code] if(!cin.good()) //here [/code] Your cin stream is corrupted when the user enters a non-digit. You need to clear the stream, output an error message, then let the user try again. The problem isn't thht the user entered … | |
Re: When a recursive function works for n, but not n + 1, chances are it's one of these 3... 1. Mathematically there's a whole in the logic. Probably not the case here. 2. You've run out of stack space. Probably not the case here. 3. You've exceeded the bounds of … | |
Re: >> p.s : i use strcmp to find the specific location for the node . There's your problem. You are going to have to write your own comparison function. strcmp has its own idea of what the order is. If you have a different idea of what the order is … | |
Re: Yes, it's possible. It would be something like this... [code] int multiplier = /* multiply by 10, 100, 1000, whatever based on the number of digits in b */ int combine = (multiplier * a) + b; [/code] Your job is to figure out how many digits b has. There … | |
Re: You have segmentation faults all over the place. That may or may not be your problem, but fix them, then try again. For example, ang[] has length 4, so valid indexes are 0 through 3. Line 12 uses an index of 4. Unless that's on purpose, change it. Ditto line … | |
Re: >> I am using Visual Studio 2010 if that matters. I don't think it matters. This is a C++ issue. If you try to read "z" into an int, cin just keeps trying and it will never get that int. You need to reset it to a good state and … | |
Re: I see a few good candidates for functions here. A function generally tries to do one and only one thing. That's a general rule with plenty of exceptions. One thing that can be placed into a function is the welcome message. That's short enough that it might be worth combining … | |
Re: [QUOTE=rithish;1767993]what is the use of malloc,calloc,realloc ?? i studied i didnt get proper knowledge .why instead of this why cant we use array???[/QUOTE] I can't explain malloc, calloc, and realloc better than all of the tutorials. cplusplus.com is my go-to site. [url]http://www.cplusplus.com/reference/clibrary/cstdlib/malloc/[/url] As to why you can't use an array, … | |
Re: newWord has length 0, so that's a seg fault. [code] newWord[x++] [/code] Try appending a character using the += operator instead. [url]http://www.cplusplus.com/reference/string/string/operator+=/[/url] | |
Re: An issue that is not part of your question: what about ties? Also, this is a boolean function. It should return true or false. [CODE]return cout << "Player 1 Wins!" << endl << endl[/CODE] doesn't make sense. As to your question, either make an Ace's rank equal to 14 or … | |
Re: Lines 17 and 19. "7" is an illegal index. You want the beginning of the string, not the end anyway, so use 0, not 7 as the second array index in lines 17 and 19. And since it's 0, you can actually drop that second index. [code] scanf("%s", colour[i]); [/code] … | |
Re: Line 14. "/" is a legitimate C++ operator, not a comment. You'll be treating "8 / 2" as a partial comment. You have at minimum 4 tokens: "//", /*", "*/", "\n". Three of them are multi-character, so your code is going to have to be more complex than reading in … | |
Re: >> in this code, when i give array of 26 or 27 then it doesn't work, but when i give 28 or higher it works properly as i want, why is this so ? although i am using only 26 character array. then why is it working when it's size … | |
Re: Well I suppose you'd pass it all of the arguments except for the first one and it would expect exactly one argument (the directory), and if it got more than one, it would return an error. Or just assume they gave you the right number and pass it a string. … | |
Re: Repost the formatted code with code tags. Code is unreadable without code tags. [noparse] [code] // code here [/code] [/noparse] | |
Re: [QUOTE=hello2419;1762957]Im wondering would anyone be able to help me with making a scoreboard in c++ for a football game...Any help would be great as i cant find any info on the net.[/QUOTE] Details, details, details. What data needs to be stored? How is the data stored in RAM? Are you … | |
Re: Can't get what to output? No functions are called. You just read in a string and don't attempt to print anything or call any functions and the program ends, so the program should run "fine" as you say, but not really do much. Is the question how to convert a … | |
Re: Before tackling your question, you need to get the thing to compile with what you have and follow the spec... [quote] [COLOR="Red"]Double[/COLOR] data field named annualInterestRate that stores the current interest rate. [/quote] Now your code... [code] private: int id; double balance; [COLOR="Red"]double[/COLOR] annualInteresetRate; [/code] So far so good. But … | |
Re: Keep in mind that the NULL terminator is less than '!'. | |
Re: I'm not sure I understand the algorithm. In particular, line 12 appears to have no effect at all. You change the value of a local variable, then don't do anything with it. In line 11, basePos is 1, so you're multiplying by 1. Again, no effect. It seems like you … | |
Re: Nothing jumps out at me for why it doesn't work. The algorithm isn't an efficient one, but at first glance it seems like it ought to give the desired results. You haven't listed the data set that DID NOT work. Line 44 -- Can mode ever be higher than count? … | |
Re: [code] void MyArray::shift_elements(int index,int pl) { for(int k=0;k<pl;k++) { int temp; for (int i=0; i<(index -1); i++) { temp = storage[index-1]; storage[index-1] = storage[i]; storage[i] = temp; } } }[/code] Any shifting algorithm that requires swapping or a nested loop is inefficient. Do it all in one shot. If you … | |
Re: I dislike giving and getting anonymous rep. One should back up one's opinion. Also if you're repping someone, they can't really "improve" whatever it is you want them to improve if they don't know the reasoning behind the criticism. That said, sometimes (OK, often-times) I'll down-vote or upvote someone anonymously … | |
Re: Delete lines 14 and 15 and see if the program compiles. If it does, then you know there's a problem. Besides, you initialize balance in line 14, then create the object in line 18. I'm seeing a problematic lack of a default constructor for this class. If you care what … | |
Re: If it returns a "garbage" value, there's a very high probability that it isn't returning anything at all, so check that function to make sure everything returns a value. Stick a debugging statement after line 112... [code] cout << "Uh-oh. Should never get here.\n"; [/code] If that line prints, that … | |
Re: Okay, then it should be in the same directory as a.out. It gets created on line 82. If it doesn't, line 85 should print. Have lines 89 and 90 print to standard out just to confirm they are executed. Add a cin.get() or two after line 90 to pause the … | |
Re: Line 18 doesn't make any sense. Are you sure this program compiles and runs? Line 22 -- why are you appending to the file instead of overwriting? Lines 31 and 33. [code] encrypted += line[i] ^ (int(key)+i); file2<<encrypted;[/code] I imagine "encrypted" is going to end up having all sorts of … | |
Re: It all depends on your demeanor and approach. If you come up to a "senior" as a rookie and have a know-it-all attitude, no one is going to want to hear it, regardless of whether you're 100% correct regarding the code. You haven't made your bones yet. If you're more … | |
![]() | Re: [QUOTE=stinkypete;1746346]Does anyone have an algorithm that generates all 10-digit integers that have at least one digit repeated? Trawling through all 9000000000 of them and checking them individually is too slow. Thanks.[/QUOTE] 10 digit number, 10 digits, none repeated, sounds like you can generate all permutations of 0123456789, then throw out … |
Re: >> However, chi_squ_end[10000000] bugs me. A lot. Ditto. I'm not sure whether this is complete, but at least the way you have it now, I see no reason to have it as an array. It seems like you can simply substitute a single variable for it. As far as I … | |
Re: >>AllocatDiff2 = 100 * -0.05; Looks negative to me. Something else must be going on. Post more code and a fuller explanation, particularly the type of AllocatDiff2. | |
Re: [QUOTE=christian03;1748818]please tell me step by step procedure to how to delete the thread that i post ?? please help me guys.[/QUOTE] You can edit a post within thirty minutes and that's it. You can PM the admins, but it's guaranteed that they won't delete since you haven't given a reason. … | |
Re: To my mind, I can't see any reason to use a string as storage. As you mentioned, in order to use it at all, you have to constantly convert it back and forth. A vector of unsigned ints and a bool for the sign seems better. Just think of it … | |
Re: Lines 12 - 19. Having a NESTED loop with strtok as an inner while loop defeats the whole purpose of strtok, particularly the way you have it. Suppose you have three words in the string. For i equals 0, the inner loop from lines 14 to 18 will execute 3 … | |
Re: Line 31 -- i is generally a loop counter variable. There is no loop (as per your instructions), but there is also no recursion. Why does the "prime" function return a long int rather than a bool, particularly since it can only return a 0 or a 1? Line 47 … | |
Re: My guess would be a seg fault. Check your array indexes. In particular, check line 26. Make sure it's what you intend. [code] for(int j = 0;world[i].size();j++) [/code] | |
Re: I've never run into this problem, but Microsoft and Java both have pages dealing with it. [url]http://www.google.com/search?hl=en&source=hp&q=Error+1721.+There+is+a+problem+with+this+Windows+Installer+package.+A+program+required+for+this+install+to+complete+could+not+be+run.+Contact+your+support+or+package+vendor.&btnG=Google+Search&cts=1265877713403&aq=f&aqi=&oq=[/url] [url]http://www.java.com/en/download/help/error_1721.xml[/url] [url]http://support.microsoft.com/kb/891985[/url] | |
Re: >> the enqueue function works fine. How do you know? Lines 50 and 55. I see the same line in both paths of the if-elese statment, which suggests either one is incorrect or the lines should be removed from the if-statement and placed after it since both paths cause identical … | |
Re: >> Are they allowed to do this? DW always say that they're not allowed to delete a member account. They've said it, but they've never cited a law that states that to my knowledge. I'm guessing it's more along the lines of an agreement they have with whoever pays them … | |
Re: What were you hoping it would print? If p is located at 0x1000, then "dcis" will be from 0x1000 to 0x1003, then the NULL terminator will be at 0x1004, and p will point to 0x1005, so it will point PAST the character array. "%s" is located at the next available … | |
Re: [url]http://www.cplusplus.com/reference/clibrary/cmath/pow/[/url] There is no pow(int, int) in cmath. You can either write your own or typecast an int to a double and use one of the ones provided by cmath. [quote] double pow ( double base, double exponent ); long double pow ( long double base, long double exponent ); … | |
Here's the code. Uncomment line 9 and you get the following error. [quote] ISO C++ forbids initialization in array new[/quote] Leave it commented out and it works just fine. I'm not sure why it has a problem with one but not the other. Each object is a 16 byte array. … | |
Re: >> There are currently no elements inside the vector (If that makes sense?) Makes sense to me. >> You need to resize the vector to M, then [COLOR="Red"]for each[/COLOR] element in [COLOR="Red"]the[/COLOR] vector, you need to resize each element to N, get it? >> Shall I implement [COLOR="Red"]two[/COLOR] for loops … | |
Re: We can't run it without the input file. The most obvious first debugging technique would be to figure out what the value of TempChar is. Do that by printing it out, but typecast it to an int to make sure it prints. Then look up the value in the Ascii … | |
Re: >> I guess #include <ctime> has something to do with: [B]srand(time(NULL));[/B] but I can't figure out the connection between them. See this link... [url]http://www.cplusplus.com/reference/clibrary/ctime/[/url] Scroll down a little bit and you'll see there is a function called "time". [url]http://www.cplusplus.com/reference/clibrary/ctime/time/[/url] You are using a function called "time" in your program. The … | |
Re: Right off the bat, look at lines 45 and 46. Line 45 -- Print i. Line 46 -- Check to see if i is prime. It isn't. Uh oh. How do I un-print? Line 46 -- Calls a non-void return type function and... does absolutely nothing with the return value. … | |
I have a base class and a derived class. The base class has an int called a that needs to be initialized. I want to create an instance of the derived class, so I call its constructor and pass it an int. I want that to call the base's constructor … | |
Re: [QUOTE=Captain Jake;1731728]OK, we know if we pull out the ranking list, we can see the one with the maximum post, reps or solved threads etc. But this is not about that, its about the people's choice, so who do you think is the best among the big boys here. (Multiple … | |
Re: >> i have almost done it using a series of loops but i cannot seem to get the offset write with the buffer, and it is full of bugs. Sort of hard to debug when you haven't posted it, yes? |
The End.