1,608 Posted Topics
Re: game[1]&&game[2]&&game[3]==play That's wrong. && can't be chained like some other operators can be. Change it to :[code] if( (game[1] == play && game[2] == play && game[3] == play) ||............[/code] | |
Re: Follow your includes. HashTable.h includes sList.h, but I don't see an sList.h. I do see a List.h, though. Same in List.cpp, you include sList.h instead of List.h. | |
Re: Frist, it's int main(), not void main(), for portability purposes, meaning, even if your compiler lets you use void, don't. Second, you need a closing curly brace between the end of showplalyer() and the first line of sortplayList(). Third, you need to indicate what type playlist[] is in the first … | |
Re: [code]ptr = new char *[width]; for (int i = 0; i < width; i++) { ptr[i] = new char[height]; }[/code] Code for a 2 dimensional array of char that could be sized to any width and height would stop there. The rest of what you have looks like you would … | |
Re: >>I have to use character arrays instead of strings. I must use the linear search That pretty much precludes use of a map. It also means you can't use STL strings within a struct, and may preclude use of a vector to hold the structs, too. You could use a … | |
Re: You already have access to arrays and they go great with loops when you want to do the same thing over and over and over. You know you want to get and manipulate information on 4 students. So I'd use a loop to get the same information four times by … | |
Re: Apparently the file/program, whatever is located on the D drive in your computer, not the C. It may be that you've partitioned your drive or you have a external drive or something else. You should be able to go someplace to look at the drive contents in the computer. I … | |
Re: [code]hours[0]=car1; hours[1]=car2; hours[2]=car3; int b; for( b = 0; b <= 3; b++ ) hours[b] = b;[/code] Why are you bothering to assign values to hours in the first three lines if you are just going to overwrite them in the loop? The loop tries to enter 4 values int … | |
Re: In a word, portability. int main() is the standard and therefore will work on any compiler which is compliant with the standard. void main() may work on some compilers, but isn't gauranteed to work on any, whether they are compliant with the standard or not. Besides, int has one less … | |
Re: nodeCount, leavesCount and singleParent can all be written using a similar footprint. First declare variables in the tree to act as counters for the number of nodes, the number of leaves and the number of singletons and initialize them to zero in the default constructor. Declare the functions with private … | |
Re: Use pencil and paper to work out your logic before trying to write the code. It might look something like this:[code] assume: a seat equals an element of the array if value of an element in the array is zero, then seat is available logic: if(decision == 1) if no … | |
Re: At least this is wrong: list = pivot; pivot is declared as an int and list is declared as an int array. You can't assign a single into to an array like that. The same holds for these: list >= pivot list < = pivot etc. | |
Re: In Invoice.h you declare this function: void print(Invoice) const; However, I don't think you can use Invoice as a parameter to a class member funtion in the Invoice class delaration because the class hasn't been fully declared yet. You can have a pointer to class type in the class declaration, … | |
Re: You could probably use any flavor of loop you wish. Generally while loops are used if you aren't certain of the number of times you want to loop whereas for loops are used if you do know the number of times to loop. Do/while forces something to be done at … | |
Re: First, it's int main() not void main(). Your compiler may let you use void, but it's not a wise idea to do so, and it's even one keystroke less to type int rather than void. Second main() usually has two arguments. You can type them in, or leave the parenthesis … | |
Re: That's a better description of the project, but you could have posted it in your original thread. As I see it the trick is to keep track of the original element indexes after you have sorted the array. I can think of two ways to do that. First, copy the … | |
Re: In getlargest() count will act as the index of the element with the largest rainfall for that year. Since count is passed to getlargest() by reference you don't need to return anything if there are no other requirements of the function. Use some counter variable other than count to control … | |
Re: first, you need to enclose the body of a case statement in curly braces if you want to delare a variable within the body of the case statement. The best answer why I can give you is "because". The algorithm for deleting an arbitrary node from a singly linked list … | |
Re: I'd concatenate the name portions into a single string before output, then print that concatenated string with field width 30 (or whatever) left justified and fill with space char. Then output score with field width 3 right justifed and fill with space char and grade field width 2 right justified … | |
Re: Neither you nor your compiler are being very helpful. Please give some idea about where line 119 is in your code. That's the first place to look. It may not end up being the place with the error, but chances are it's in that neck of the woods. I could … | |
Re: use a loop starting at index zero going to length of string. In body of loop output current char and index using whatever format you want. | |
Re: during the input loop t is the index of the elements going into the arrays x and y. However, after the input loop t is the number of inputs read from the file. Therefore after the input loop t is not a useful index for accessing loop elements as there … | |
Re: Don't use the return value of eof() to control the input loop. Use this instead: while (getline (myfile, line)) >>How can i get the digits out from file You have to parse the input, either during the read or after. Looks like the file is a line with a score, … | |
Re: There is more than one error in the program. The one you have been informed of first involves the constructor you have written. In the .h file file you declare the constructor taking a string: Course(string corsename) and you define it inline by placing the {} after the above line … | |
Re: use a loop asking for input, stopping only when input is valid. Within the loop use the >> to attempt input into a numeric variable. check validity of the istream after the attempt. If it is in the fail state then assume the input was invalid and call the istream … | |
Re: try calling file.clear() after the file is read and before you close it. It's easy to do. It might work. It might not. don't use the return result of eof() to determine whether the body of the loop will be entered. | |
Re: >>It repeats the "Enter the next row:" statement more than once for each time its executed. Looks like it should be printed 9 times according to your code. Specifically when: m = 0, n = 0 m = 0, n = 1 m = 0, n = 2 m = … | |
Re: Once you enter an value in an array it's there for the duration unless you change the value. One option you have is to keep track of the number of valid values in the array using another variable. All the valid values in the array will be at the indexes … | |
Re: cout is a global object. It isn't passed to the display function. It isn't declared within the display function. Therefore there is only one copy of it. On the other hand, your display() function does declare the ofstream object locally. Since display() is recursive, that means you are trying to … | |
Re: You don't need an h file if you do something like this: void someFunction(); //prototype int main() { someFunction();//call } void someFunction() //definition {} You need all three: prototype, call, and definition. If you define the function before main, then you don't need a prototype. >>'ctid_t' is used as a … | |
Re: while (depth == 0); { //do something } Take that ending curly brace down to the line with END LOOP. Remove the semicolon after the first line, too. Change this: int calculation; int area (l * w); to this: int calculation = area (l * w); and similar in the … | |
Re: The only header file you will need is iostream. To accomplish your task you will need to isolate the individual digits as either single digit ints or as char and then display them one at a time with as much space between them as you wish. | |
Re: You should start at the beginning. Learn about the different native data types available in C++. Learn about arrays, strings and lists as common containers for holding information. If the values you will use will only be digits one and zero and you want to manipulate them, then you might … | |
Re: It takes some work. C++ ostream manipulators take practice getting used to. GUI custom controls are probably the easiest way to get things neat and tidy, but it takes a fair amount of knowledge in C/C++ to get comfortable using that type of code too. A good reference book with … | |
Re: One of the other approaches is to never accept input as a numerical type. Only accept input as a string. Then parse the string after input for it's validity as a numeric value and convert the string to the numerical type as desired if it's valid. | |
Re: I'd try using strings or develop an internal representation using ints, but a display format that is right justified and filled to left to a specified field size using zeros by using ostream manipulators. | |
Re: You can probably accept input as a string and indicate error if length is longer than four. Bottom line, you can't prevent user from not goofing up. All you can do is try to handle it if it is a goof. | |
Re: And here's another one, in the following snippet k stops when it is more than what? Or, if you prefer, complete the following if k is less than or equal to what: for(k=0; k<= ; k++; ) | |
Re: your coded logic reads something like this:[code] get information from user, but ignore it for as many songs as there are in the list if list is longer than two delete the second song in the list else assign a value to a flag but never evaluate the flags value[/code] … | |
Re: Just as an aside, in this economy a short might be a more accurate variable type than an unsigned long for the balance. Hopefully we don't see the day where char types have enough memory to successfully handle the balances! | |
Re: 1) In your current version of GetNth() what role do the variables number and searchCount play? If you're not going to use them, then delete them. 2) You declare GetNth() to have return type int but on line 28 when you call the function you ignore the return value. If … | |
Re: As mrboolf said you probable want to send events and numDays to eventDays, not declare them in eventDays. It may well end up looking something like this:[code] void eventDays(string events[], int numDays[], int size) { //display elements of events in a menu //have user input event number from menu //display … | |
Re: Probably, you can check it out pretty easy. Be careful of the word size. size is frequently used to indicate the actual number of elements currently in the vector as opposed to the number of elements for which space is allocated for vector use, which might be called capacity or … | |
Re: 1) Welcome to Daniweb! Please take a moment to read the anouncement at the top of the board about using code tags when posting code. The code tags will help preserve the indentation you should be using when writing your code when you post to the board. 2) You program … | |
Re: := looks like shorthand for assign. The rest seems pretty much straightforward. Input n values, n = 5 in this case assign the first value to temp for the rest of the values //you can do the rest. | |
Re: Yes you could rewrite the program to handle dates instead of time. You would need to determine the format(s) you want first. Then start with the basics and write just one function/method at a time, testing as you go. You can post post pertinent code, error messages and questions about … | |
Re: Read up on loops as they are likely to figure prominently in your program. Provide a better description of your program, it will help you help yourself as well as helping others help you. Show some effort besides just posting your version of the problem description. In particular provide code … | |
Re: an int plus an int will always be an int. Have the program do the calculation and store it in an int called temp. Then get user input in an int called answer. Then compare the two numbers using the equals operator within an if conditional with the body of … |
The End.