1,608 Posted Topics
Re: [code] char rowComp = 0, colComp = 0; while(colComp <= COL) { while(rowComp <= ROW) [/code] Without my ESP hat on I can't tell what the error messages are that you are getting. But I can tell you that the above should probably be changed to: [code] int rowComp = … | |
Re: A simple empty main() is always a good place to start! Since this isn't a math or physics forum, by t square matrix do you mean a matrix with an evern number of rows and columns? If so, and if you use notation similar to (0,0) to denote any given … | |
Re: The string class overloads the [] operator so individual characters can be accessed just like with a char array. the c_str() method will return a const char* to the char array embedded within the string object if you want to change the string into a char []. You could do … | |
Re: Two common places for a programmer to use the copy constructor are: MyClass one; //uses default constructor MyClass two(one); //uses copy constructor MyClass three = one; //uses copy constructor The compiler will also use the copy costructor and you aren't aware of it, unless you are intimately familiar with how … | |
Re: >>where do I put "string::c_str()" in my code? Whereever you need to uncover the C style string hidden in a STL style string object, like when you want to use atoi() to convert an STL style string to an int, etc. Also, using the return value of eof() to control … | |
Re: >>print the numbers in order? First you need to specify what order you are going to print them in and then where you are going to print them. If you want to print them to file in ascending value then you will need to store them all in a container … | |
Re: I think this will work. Let's change it up a bit. Say I put some numbers in a paper bag, gave you the paper bag and said take the numbers and tell me what the biggest and smallest number in the bag was. One way you could do it is … | |
Re: You need to store each set of inputs in some sort of container, sort the contents of the container, then print out the sorted values. There are several containers that could be used, though for beginners arrays seem to be the most common. There are several sorting protocols that could … | |
Re: I have no idea what the Lee algorhithm is, or isn't. However, given your description and your post, I presume you could do something like this. The pattern presented can be considered as a series of lines on top and a series of lines on bottom where Each line has … | |
Re: Who knows how much, if anything this will help, but the user can select a value for a variable called choice which can range from 1-3 and is used as an index in an array that has three elements which can have indexe ranging from 0-2, so when user selects … | |
Re: three calls to getline() with the first two using : as delimeter and third using newline. Then convert each string obtained into numerical value using sprintf() or strtol() or atoi() or stringstream, etc. | |
Re: 1) use code tags when posting code to the board 2) intialize cnt to 0 every time count() is called 3) it isn't polite to highjack someone elses thread. Though there is some similarity between your problem and the original problem presented, it's not the same and a new thread … | |
Re: I'd use serial calls to getline to parse the file. #1 read information up to = and ignore input #2 read information up to : and save #3 read information up to : and save compare #2 and #3 and do whatever #4 read informtation up to newline and ignore … | |
Re: Of course the other way is to use STL string objects and just use the overloaded logic operators built into the class, but I don't think that's quite what your question meant. | |
Re: the baseline behavior of fgets() is that it will read in the newline char in addition to the alphanumeric char and other whitespace char if there's enough room in the array. So I here's what I would try. Declare the target string to include two more than the max number … | |
Re: I'd try declaring the array using pointer to pointer syntax within the declaration of the struct. Then within the constructor I'd use dynamic memory to declare the memory. The dimensions could be hard coded or "user supplied". The destructor would probably release the memory declared. Assuming you are using C++ … | |
Re: You could use the division and the modulo operators in sequence to generate indivual digits which could be used to increment counters in an an array of ints and then print out the array values with the associated indexes when done. But that's just a guess as to what algorhythm … | |
Re: Look up C output format specifiers. The number will be stored to whatever degree of precision that is allotted to type double, but the degree of precision can be dictated on displaying the value. | |
Re: Please don't start a second thread for the same problems discussed in a prior thread. [code] while (getline(inFile, list )) line.substr(0, 6) [/code] Where/how is the return value of substr() stored in an array of strings? If you read the file using this code then the array of strings representing … | |
Re: declare an array (or vector) of strings to hold the original strings and a second array (or vector) to hold the 6 char strings. Use a loop to read the first 6 char of the originalString[i] into sixCharString[i] one at a time accesses each char using the 2 dimensional [][] … | |
Re: If argc equals 5 then the last valid index for argv is 4, not 5, since array indexing is zero based. That also means that argc - 1 should probably be argc - 2. Typically you would just declare the ifstream once by declaring it outside of the for loop. … | |
Re: Pointers can be tricky until you've used them a while. Basically a pointer is an address of something. There are three ways you can get the address of something: You can use 1) pointers: int * a; //means the address of an int variable is held in a 2) the … | |
Re: >>its not giving any error Wow. What compiler are you using? I'm surprised it compiles at all. You use a variable in workSieve that isn't declared. Remember that b isn't the same as B in C/C++. | |
Re: Use variables. int numberOfHoursUsed; int baseHours; double excessFee; double baseFee; double totalFee; double overchargeRate; int overchargeTime; baseHours is given for a given program basFee is given for a given program overchargeRate is given for a given program overchargeTime is numberOfHoursUsed minus baseHours excessFee = overchargRate times overchargeTime totalfee = baseFee … | |
Re: Welcome to Daniweb! I'm having trouble telling where option 1 and 2 separate and whether there is a third option. Your description however sounds pretty good. Some folks here would prefer to see you use something like sprintf() or a stringstream to convert strings to numerical values, but atox() family … | |
Re: I'd read in the file one field at a time storing the information in a struct that I'd then store in a container. As I was reading in the first field I'd check it against the current longest name. When I'd read in the entire file the longest name would … | |
Re: >>when I try to manipulate the first node in the list, nothing happens to the first node in the list back main function, so it seems to be changing that locally, however main doesn't seem to acknowledge these changes ... could anyone please tell me how can you change the … | |
Re: [code] //set loop pointer to start of loop loopPtr = listPtr; //look at all nodes in list while (loopPtr != NULL) { //if you find it if(loopPtr-> item == Item) //you can stop return true; else //otherwise look at next node in list loopPtr = loopPtr->next; } //if you get … | |
Re: The basis for a solution to this project is given in the parenthesis at the end of the problem statement. If you use the modulo operator on two ints like this: a % b then the return value is the remainder of a divided by b. So if a were … | |
Re: Welcome to Daniweb C/C++. Please read the announcement at the top of the page regarding use of BB tags or the watermark in the Message box regarding the use of code tags specifically. Using these tags will keep the formatting of your code as you post it. If you don't … | |
Re: In my experience it means the linker isn't able to find a function/variable in any of the header files included. Often it means the necessary header file isn't included or the function/variable isn't available in the files included. | |
Re: Read the input into a string, not a numerical variable. Then validate the string. Once validated convert the string into a numerical variable. | |
Re: [code] char board[7][7] ; for(i = 0; i < 7; ++i) for(j = 0; j < 7; ++j) board[i][j] = '*'; //fill board with *s turn = player1 = X; row = 2; //using choices 0-6; col = 5; //using choices 0-6; board[row][col] = 'X'; //display board for(i = 0; … | |
Re: In the OPs recent posts he consistently does this: [code] for(i=0;i<=5;i++);{ for(j=0;j<=5;j++);{ [/code] Unfortunately the semicolon stops the loop before the opening braces become evaluated so they are worthless. If you want to do something in the body of the loop don't have semicolon right after the control statement. It … | |
Re: A map would be one way to do it. If you don't know about maps, then using a sequence of arrays can do it, too. After your initial array is sorted it will look like this: A => 33566 Now you could set up an array of unique numbers in … | |
Re: Target is declared as a string but you treat it as a single char in the call to scanf() and then you treat the single char as a string in strcmp. You similarly type mismatch single char for strings in other scanf() calls, too. What's the feof thingamabob? You need … | |
Re: push_string() could use a for loop like you have in main() in push_string(). You are basing your stack on a list and adding each new node to the front of the list, which is fine. However, the very first node in the list has to be somewhat different than any … | |
Re: Is this more what you're trying to do [code] //read each char of Line while (Index <= Length(Line)) { //if current char is not a space if (Line[Index] != ' ')//; { //write current char to screen WriteChar(Line[Index]); Index = Index + 1; } else //if current char is a … | |
Re: Given the use of the STL string class and the iostream objects I'd say the program is using the C++ language and the C language time header file since templates and iostream objects cannot be used in C. I'm not sure the STL string header includes the iostream header, though … | |
Re: >> balance -= ( monthlyInt + principalPaid ) I'd like you for my banker if you are going to deduct my monthly interest payment from my balance in addition to primical payment! | |
Re: A brief summary of the usefulness of pointers. 1) They can let you use the information in an entire 5kb array (or any other memory hog) in another function having to copy/send only 4 bytes instead of the entire 5kb (or whatever). 2) They allow you to use the (usually) … | |
Re: There is no easy way to limit output to a given number of decimal places in C/C++ that I've seen. After wrangling through a rather lengthy discussion previously, I'd store the whole number part of the given number as an int through casting, then multiply the given number by 100, … | |
Re: You may need to use preposser commands like : #include <string> using namespace std; Line 11 : You're sending a literal string to itsVowel, not a string entered by the user. In fact there is no way for a user to enter a string in this program. Line 22: The … | |
Re: The logic of your program seems reasonable but your use of variables seems weak, for example where did datafile and ch come from; and you need to look up the declaration of the istream open() method--is it supposed to be myinput.open(sesame?) or is it something else you're trying to open, … | |
Re: You're doing a shallow copy of array to array2. When you free the memory for array you also loose the memory you were pointing to in array2. Do a deep copy of array to array2 by assigning independent memory to array2 using malloc() like you did for array, and then … | |
Re: Here's another approach that might work. Use a list to hold the words and their frequency since you don't know how many words you will have and you are using C so STL vectors won't help. Each node in the list would have a char * for the word and … | |
Re: Yes. C++ is the language and Visual C++ is an Integrated Development Environment that contains all the software you need to write programs with the C++ language. You can use other software to write programs using the C++ language if you want, though many people like, or are required to … | |
Re: You'll also need a variable to hold the current guess, a protocol to access each element in the char array and determine if it is equal to the current guess and a variable to keep track of how many times the current char is found in the array and a … | |
Re: [code] if (B == 0) { C = 1; else if (prime % primes[b] == 0) B = 0; } [/code] Remove the { and the } or do this [code] if (B == 0) { C = 1; } else if (prime % primes[b] == 0){ B = 0; … | |
Re: Welcome to the DaniWeb! You should know it's discouraged to do homework for you. However, demonstrate your efforts and many people will help guide you by offering corrections, comments, etc. For any project it's important to understand the problem. So, for example do you know what the sympbols ^ and … |
The End.