138 Posted Topics
Re: The function identifier says it all. [CODE]int total(int value1, int value2)[/CODE] The 'int' at the beginning tells that your function returns an int value when called. Therefore, it is logical that an 'int' value is return when you call the function at line 8 of your main method. [CODE]total(num1,num2);[/CODE] You … | |
Re: Hi nhidman, what are you trying to achieve by splitting and then merging the audio file? One simple example has been given by prvnkmr449. That is to treat the audio file just like any other binary file. Split them into the number of chunks that you like. Then reading each … | |
Re: Beware of the code [CODE]chsum = ch2+ch3+ch4;[/CODE] There may be buffer overflow due to the limitation of data type [B]char[/B] which can have maximum value of 255 only. | |
Re: Logically thinking, it is a math problem. Fortunately, C/C++ has a built-in library catering for common mathematical needs. You may want to look into these two functions: floor() and ceil() Both from the math.h library. | |
Re: You may want to have a look at WMI (windows management instrumentation). It provides an extensive API for accessing your systems information. | |
Re: Its good to see that you have the functions well separated. May I suggest you perform some unit test to ensure that your functions are returning the expected results? If each function are doing fine, then, most likely your program has some logic error. | |
Re: Based on my understanding of your question, you are requesting help to check on your main() function's logic. Hence, I will comment only on the main() function part. 1. Why do you need to declare a ChildGame object in the do..while loop? All you need is only one game. 2. … | |
Re: You have to add an else statement after line 9 [CODE] if (text.empty()) { ++nl; } else { // to save, assign text to a variable here } [/CODE] It is because the text will be overwritten in each iteration at line 4. Logically, when user presses enter twice, the … | |
Re: Are you getting the concept of stack (data structure) wrong? You may get a clearer picture of how stack work at [URL="http://en.wikipedia.org/wiki/Stack_(data_structure)"]http://en.wikipedia.org/wiki/Stack_(data_structure)[/URL] Still, I could not figure out your example. Would you mind giving a clearer explanation? | |
Re: Did you try to access your month, day, year variable directly from outside the class? Whats the error that you get? Please note that your month, day, year variable are declared as int but your accessor methods are returning double. (this does not flag an error but it is not … | |
Re: Your code should look like below if you want to return all balance for an account. [CODE] int userInput = 0; cout<<"Please enter the account number you would like to search"<<endl; cin>>userInput // iterate through all accounts to find for(int i=0; i<10; ++i) { // check if account number found … | |
Re: Reference to read text from file [URL="http://www.cplusplus.com/doc/tutorial/files/"]http://www.cplusplus.com/doc/tutorial/files/[/URL] Use getline() to read one line at a time into a string Then, use find() of string class to check if the text is found [URL="http://www.cplusplus.com/reference/string/string/find/"]http://www.cplusplus.com/reference/string/string/find/[/URL] Post your code attempt in here and many people are more than happy to help you out. | |
Re: I do not think you can do that. A pointer of list pointing to a queue. That should not be compatible. Btw, what is the compilation error message that you get? | |
Re: A simple search in any search engine would have presented the answer to you. You may want to refer to this site for some reference [URL="http://www.cplusplus.com/doc/tutorial/files/"]http://www.cplusplus.com/doc/tutorial/files/[/URL] | |
Re: Have you run your program and verified that the result is as intended? Will the program ever complete running? There shouldn't be any problem with the code you posted. | |
Re: Why would you want to initialize your const variable in the constructor class? Since they are constant and you know the values beforehand, isn't better to assign the value to your const variable at the point they are declared? | |
Re: There are only two possibility that your program does not close by itself. 1. You are running in Debug from IDE and the IDE prevents the console from closing 2. Your program is in an infinite loop Just build a release version of your program and run the built exe. … | |
Re: Since you are reading from the stdin, you should use the function gets(char *str) which reads from the stdin and does not include the new line character (\n) in buffer | |
Re: Problem is not with the code you posted here. I suspect it is a syntax error that occurs before the myprintf() function. Do check your code before that, specifically the print_str() function. | |
Re: Never ever try to access a memory location like that. You have no idea what's stored in that memory location. Anyway, how did you come up with that particular number of 0x378? The purpose of pointer is to reference a memory location where it holds a value of interest to … | |
Re: Assuming you want it to loop indefinitely (beware that this causes your program not able to end) [CODE] while(true) { // your codes here Sleep(2000); // milliseconds } [/CODE] | |
Re: First of all, your file should be written in binary which contains nothing but the objects of your c structure. Here's a breakdown of what you should do: 1. Open the file in binary format and read to the end of the file. Make sure the size is correct (correct … | |
Re: Whenever possible, try to avoid nested loop as they have a worst-case of O(n2) - Big O n square. In simple terms, it has bad processing time because your worst case for nested loop is n square iterations. When your n is sufficiently large, your logic will take a very … | |
Re: Start off with some code and I'm sure everyone here are willing to help with your problem. | |
Re: You must use 'delete' on every 'new' variable. Thus the second is one to follow. It is a good practice to make your pointer to point to NULL after you have deleted the object to prevent your pointer pointing to unspecified location. [CODE] void SomeClass::someMethod() { AnotherClass *object = new … | |
Re: Yes, as demonstrated by Aia, you do not need to deal with incrementing pointers yet. You may pass in the address of a particular CITIZEN object [CODE]display_cit(&cit[x]);[/CODE] Then create a pointer as parameter to be able to access the passed in object's value [CODE]void display_cit (CITIZEN *individual)[/CODE] | |
Re: I your case, I do not see why is there a need for you to create a list of pointers. Why not consider having a list of the object node and only maintain one pointer to your list? Ain't it more efficient? | |
Re: If all you want is to select the maximum and minimum, only one iteration is sufficient. 1. First assign the first element of array as min and max. While iterating, 2. compare if the current value is less than min. If yes, replace the min value 3. compare if the … | |
Re: To move through a linked-list, you will need an iterator. In your case of deleted every third node, simply use a counter which will increment after traversing each node. Delete the current node when your counter reaches the value 3. Then reset your counter to 1 upon iterating to the … | |
Re: In addition to thelamb's explanation, that means you have to remove the type name in line 33 and line 34. Also, remember to remove the '&' (address of) symbol. If you were to include this symbol in the caller function, pointers have to be declared as your function's parameter. For … | |
Re: Why not think about the logic. Do not worry too much about the syntax and things. Try to present your logic here and I believe many of us here are more than happy to give you guidance in turning the logic into codes. | |
Re: In your find function, add a line to return -1 after the for loop. This will indicate ID not found/invalid ID. Then in line 23 after you get the value for variable [B]place[/B], add this checking: [CODE]if (place == -1) { infile >> id; continue; }[/CODE] This will skip the … | |
Re: [QUOTE]I then insert the edge into a min-heap. But, like I stated above the parse code works in NetBeans and Dev c++, but it doesnt work properly in a linux terminal.[/QUOTE] What do you mean by the statement above? Are you trying to compile your code using GCC in Linux? … | |
Re: viziroth, I'm quite confused as to what you are asking here. I believe your question can be simplified. Do point out what you want to ask and make it clear. Thanks. | |
Re: To start things off, why not you post some logics about the code that you have implemented? | |
Re: It is better for you to implement your own. As written in [URL="http://www.cplusplus.com/reference/algorithm/find/"]std::find[/URL], if value is not found, the last will be returned. In this case, when the last index is returned, you cannot tell if the last item matches OR it is not found in your list. | |
Re: Have you singled out that the slow performance is due to the sort operation? I suspect that the slow response may be due to the repainting event as highlighted by nille_nerholt. Do you mind to share with us what sorting algorithm are you using? Have you tried to use the … | |
Re: The variables you're storing to the TXT file [B]code, no_of_parts, sum_assignment[/B] does not contain any value. Those values stored in the function store_data() is locally-scoped. Meaning, they are accessible only inside the function. Therefore, even if you declare the same variable name in your function Save(), the application is not … | |
Re: A little piece of advice: [B]do put all your variable declarations at the beginning of the function[/B] It helps a lot in terms of readability and program maintenance in future. | |
Re: A switch case inside another switch case is strictly a no no. It goes to show that your program is not modular enough. You'll have a hard time maintaining it. Others will have a hard time understanding the logic. [QUOTE=caut_baia;1201091]:) yeah i omitted the "&&" [code] char letter; char currency; … | |
Re: Your variables are confusing. The [B]scrpt[/B] and [B]scpt[/B] seems to be used incorrectly. In the myfunc(), you are not accessing the passed in parameter. And why are you passing in the global variable instead of [B]char scpt[10][200][/B]? There is no need to pass global variables around. I would advice you … | |
Re: Did you forget to reset [B]pcode_index[/B] and [B]exist[/B]? | |
Re: Yes, I agree with mbulow that you can use a std::map. You may also want to consider the option of 2D array since the number of fruits supported in a cart is known at compile time. | |
Re: You are getting the compiler error because the variable [B]bAmount[/B] is printed out in line 40 before it is assigned to any value. In that case (line 40) the correct variable should be [B]AmountDue[/B] | |
Re: You do not need to put in the [B]case[/B] keyword before the default keyword | |
Re: You may want to use the modulus (%) operator for getting the index of vector to delete. All you have to do is keep adding the [B]position to delete[/B] entered by user. Hope this helps | |
Re: Hahaha... Its surprising that the code managed to be compiled! | |
Re: The main reason your program fails is because you are trying to read from your output file. You should be reading from your input file instead. [CODE]ofstream outFile("source.txt", ios::out); a1.prepare(inFile2, outFile); ifstream inFile3("encrypted.txt", ios::in); char ch; while(inFile3.get(ch)) { a1.encode(ch); }[/CODE] | |
Re: Not sure if this is what you're looking for. You can check out MDI (multiple document interface) |
The End.