1,608 Posted Topics
Re: First think of what you need that you don't already have. In this case you need an int to return when the function is over, and it should probably have something to do with what the function is supposed to do, like index or position. Then you can use the … | |
Re: To print two colums, one with evens, the other with odds. I'd separate the original array into two separate arrays, one for evens and one for odds. Then I'd loop through the arrays printing evens and odds with the same array index on the same line. If there was more … | |
Re: try null terminating the different versions of array before you try to print them to the screen. I don't believe the compiler will automatically to that for you if you explicitly initalize elements of the array. | |
Re: if (temp.num[i+1] == -99) I suspect the problem is in the above line. It's difficult to say for sure, but how do you know where to put -99 in temp.num? I suspect there is no -99 in temp.num so the above line won't work. On top of that you need … | |
Re: First thing is try a little harder to get the indentation consistent. Code is much easier to debug when it's consistently formatted. Type double is prefered to type float in most cases. If either x or y is zero, which is the same as both x and y not being … | |
Re: Write yourself a little program to test your hypothesis. It's good practice and a good learning experience. Alternatives to using a stringstream would be sprintf(), which is C style, or itoa() which is nonstandard. | |
Re: The shorter way would be to use arrays, and the concept of parrallel arrays in particular, meaning the information stored as elements with the same index in each of the parallel arrays pertains to the same candidate, so candidate[x] has totalVotes[x] and percent[x], etc. (Actually the concept of an array … | |
Re: First, I'm surprised the code compiles given that you declare StoArrayXYZ using a non-const int. You should probably have the class methods defined in a file of the same name as the header file they are declared in, but that has the .cpp extension rather than the .h extension. You … | |
Re: I'm not a tree hugger or any way expert in the use of trees. However, when I do venture into the forest I usually use a node with at least two, and often three node pointers. [code] struct node { //non-node pointer member variable(s) here //node pointer member variables here … | |
Re: std C/C++ numerical types don't recognize comma separaters. So, as vijayan has demostrated, you need to find a way to convert the numerical value to a string, then insert the commas and print out the string. There are other ways to do this basic sequence beyond what vijayan has demonstrated, … | |
Re: You can either loop through each column looking for the day with the minVar for that column, store each minVar in another array, and then search the array of minVar for the desired value when desired, OR you can compare the desired minVar value with the minVar of each column … | |
Re: In a (too) simplified response, you use an ifstream, inStream in your program, to read from the file into the program and ab ofstream, outStream in your program, to write material from the program to a file. Use inStream instead of cin anytime you want to read from the file … | |
Re: To reduce the fraction you could first find the greatest common denominator (factor) for the numerator and denominator. Then divide both numerator and denominator by the greatest common denominator. To find the greatest common denominator you can search this board or the internet for commonly used protocols. One approach has … | |
Re: switch the ors (||) to ands (&&). All of the conditions need to be true to proceed. You can decrease the number of conditionals by using toupper() to change any lower case to upper case and then just check for those. | |
Re: post an attempt and someone will help you from there. Frequently recursive functions look something like this:[code] returnValueType functionName(list of function parameters) if this is the value to terminate the sequence of recursive calls stop otherwise do something either before or after the next call to this function increment some … | |
Re: You passed a 2 dimensional array, your instructors example used a single dimensional array. Your instructors example prints out the first element of the array and then the product of two adjacent elements in the array, that is current element times the next element, as long as there is a … | |
Re: Think of a stringstream as a file you can't see. Then you realize you need to load the file with something and then you can read from it. In this case you probably want to load the stringstream with a student object and then use the output operators and modifiers … | |
Re: x can be written as (x^1)/1! Now it's in the same form as the other terms, x^exponent/exponent!, except that you need a mechanism to flip the sign from positive to negative, which can be done by using -1^(exponent - 1) with each term. now use a loop to add each … | |
Re: Are the postings direct copy paste of the code? If so, then you have two versions of << listed, one as friend and one a routine class method. Both versions in the declaration call for a reference to a list, whereas in the definition you are only using a list, … | |
Re: You've posted straightforward C++ code but the Debug Win32 bit implies you are compiling it as a windows project instead of a console project. | |
Re: You need to declare readFrac() before you call it, but otherwise it looks pretty good. Does it compile? run? give an expected answer when known input is presented? If so, then you've done your job. You could spice it up using a class to define a type called something like … | |
Re: it may be the display of the value, not the actual value itself that's the problem. Try adjusting the display with ostream modifiers like setprecision, setwidth, etc. | |
Re: This appears to be the common problem with mixing >> and getline() in the same program. The problem is probably because you call >> on line 53 before you call NewAssignment(), which is where getline() is called. Turns out that >> and getline() don't work the same. One way they … | |
Re: AStually classes and enums and structs allow the user to create their own variable types so we aren't restricted to using just native types (sometimes called plain old data types) like int, long, double, char, etc. Data structures are variables that can hold multiple examples of the same type. Arrays … | |
Re: Let's try to use pencil and paper. Say user enters pDate with value of 20101231, where the first four digits on the left are the year (2010), the next 2 digits to the right are the month (12) and the last 2 digits going right (31) are the day. If … | |
Re: It sounds like your compiler wants you to define the default constructor since you declared it and called it. The easiest response to this would be to add a set of curly brackets after the declaration of the default constructor and rebuild/run the program again. Note that your program doesn't … | |
Re: char choice = ""; This is still a char vs string since "" is the empty string. Change '' to be a valid char. Likewise "q" is a string whereas 'q' is a char. | |
Re: Did you write the file or did someone else and you have to use what you've got? The problem is you need to have some way to separate out fields so you can place the appropriate information in the appropriate variable. The >> operator separates by variable whitespace char or … | |
Re: How about something like this:[code] //create a new list by deep copying data in source list to new list //keeping the source list intact OrderedSListT newList; //declare the new list SNode * temp = Source.mHead; //start at the first node in the source list while there's a node to copy … | |
Re: Create an int variable called currentDayOfWeek and initialize it to the appropriate value for the first day of the calendar. Every time you create a new day advance currentDayOfWeek by one and when currentDayOfWeek is the last of the week, reset back to first day of the week. Keep track … | |
Re: In C++ the input is stored in a buffer of characters until the enter key is pushed. When the enter key is pushed the various input methods of cin are called to remove the information in the buffer until the buffer is empty or until the input stream, in this … | |
Re: The first and last lines of the calendar are different from the others in that they can have empty spaces in them. The last line can be handled by stopping output for the line, but the first line needs the offset printed before the output starts. The number of days … | |
Re: >>char *rstring; This is not a string. It is a pointer to type char. In order to use rstring as a string you need to give it some memory. The segmenation fault comes when trying to use rstring as a string. do something like this: char rstring[256]; or this: char … | |
Re: loops and arrays (and other containers for that matter) are a match made in heaven. Put all the grades results in one or more array(s). Then use loops to do the calculations on lines 74, 75 and whereever else you need to. | |
Re: It always helps to be as clear as you can with the requirements of the task before trying to start. For example, the declaration of theArray and randArray seem a little weird. In particular I see no benefit to using a single index in an array. I would declare an … | |
Re: Here's two hints in one: it's important to declare and give variables a meaninglful value before trying to use them. It would be much easier to read and decifer if indentation guidelines were followed. | |
Re: Those tools are basic programming devices and you should know them well if you plan to keep on writing code. Using them in the context of a game makes it more appealing than just routine regurgitation of what each device is and can do. Almost all games will use them. … | |
Re: Why stop there? Pick up another book and learn more, even if it's a different language. Maybe you can learn about making games or creating simple databases or create an application to do something at work or school or whatever. You could even have some fun and get a sense … ![]() | |
Re: There is a standard function called tolower() (and a companion function called toupper()) that can be used to evaluate each char of a string one at a time and change it to the appropriate case as needed. So to use it, look up tolower() in your compilers help section and … | |
Re: Your calcution has counter running from 0 to 100, which will give you 101 terms rather than 100, but other than that it looks okay at first blush. Run your program to see what happens. To allow the user to try out different values of x you just put the … | |
Re: I see Ancient Dragon has typed faster than I and with a more precise version of what to do. As a learning experience here's a sampling of ideas I have about your code: 1) use int main(), not void main() 2) i should be an int, not a char 2) … | |
Re: Unfortunately line 12 ends main() and the rest, as written, is ignored. I'd try something like this:[code] if (x == y) sum = 2 * x; else if(x < y) low = x; high = y; else else low = y; high = x; for(int i = low; i <= … | |
Re: It's not clear to me what all of your loops are trying to do and since I'm not fluent in your native language I don't understand your comments. I can say that your use of the variable called unused is unusual and why you want to overwrite the contents of … | |
Re: Unfortunately the devil's in the details, as implied by Colezy. You'll need to post the context of where that line is used, what that line does (in detail) and whether it is code you wrote or code you can modify before anybody can do more than give a shot in … | |
Re: Read the file line by line using the version of getline() you need depending on the type of string you use. Once you have the string you can evaluate whether it is a data string or a spacer string (all *s). If it's a data string then parse it (break … | |
Re: Does integer mean the number of nodes downstream from the head node or the integer address of a given node? I suspect you want the former, but I can't say for sure. If you start with a pointer called currentPointer that is assigned the value of first how do you … | |
Re: I don't believe the ignore() method for input streams requires the enter key to be pushed before execution occurs. | |
Re: main() should have return type int. In main() you want to read the file with the ifstream you declared, not with cin. Therefore replace cin with the ifstream in lines 26-35. In addition push, pop and serve are member functions of a class and can only be called using an … | |
Re: Assume each letter (ie, char) in TOO and GOOD is a digit. The value of the digit is stable for each occurrence of the letter in the equation. Since there are 4 TOOs on the right hand side of the = operator the original equation is the same as 4 … | |
Re: what difference do you see between: execute debug load filename asseble filename The first two are one word commands and the latter two are two word commands, right? Unfortunately the >> operator only works for single word commands. Actually >> will stop input with the first whitespace char encountered, which … |
The End.