1,608 Posted Topics
Re: To expand on WaltP's post, the problem is likely due to the different behaviors of the input methods getline() and the >> operator. Input in C++ is buffered, which means when you hit the enter key to stop input into the program as desired, the input goes to a buffer … | |
Re: I'd expect a warning but not an error for unitialized variable. You can initialize present and next to anything you want as long as you change it to a meaningful value before you try to use it. Initialize it to a tilde or an asterix or something if you want … | |
Re: beware of loops controlled with return type of eof(). If everything is set up right, it is okay, but it's easy to get caught in at least a potential bug that is readily avoidable. | |
Re: I'm not sure of your proboem. Please provide sample input with expected output and observed output. My best guess as to your problem is you can't add current average miles per gallop to previous average and divide that by number of "loops" to get overall average. Keep track of total … | |
Re: Run time debugging is a big part of creating a successful program. Either use your debugger to step through the program with known input or enter debugging code, something like the following often works pretty well, and see if you can track down the problem. On line 16 of EditStockItem() … | |
Re: Unfortunately the code posted by jman2011 has multiple errors. Assuming insertion sort means sorting occurs with insertion so the new entry is put in the correct place from the get go, then you could use either an array or a list or a vector or a tree. Given the hassle … | |
Re: Assuming you aren't allowed to use the STL list class because this is a learning/teaching experience, then you should create your own linked list class. If you feel comfortable using templates fine, otherwise you can create a class for each type or include data variables for each type in the … | |
Re: Input in C++ is buffered. That means that when you type stuff on the keyboard it is stored in an internal "buffer----think array or queue" until input is terminated, usually by entering a new line char by hitting the enter key. The input waits in the buffer until an input … | |
Re: File streams work by using a pointer to keep track of where you are within a file. File streams have different "states". In order for a filestream to work it has to be in the "good" state. If the file pointer reaches EOF (End Of File) it causes the file … | |
Re: Locate the index to be "erased" by overwriting. Then use a loop to assign the data at index + 1 to index starting at index and going to next to last used index. When done the last used index will be available for overwriting (be free, "empty") as the data … | |
Re: I'm pretty sure "%s" is expecting a C style string, not an STL string object, which is what a is declared to be. Use cout instead of printf() or use a.c_str() instead of a. Mixing C and C++ I/O methods like printf() and cin in the same program isn't recommended. … | |
Re: To divide one number by another you could probably pass both numbers, say a and b, to the function with intention of doing a/b. Check if b is zero, because dividing by zero is undefined. Within the function you can declare two numbers, say c and d, with c being … | |
Re: I'm not familiar with the syntax array<int, 2>^ (I suspect it is from C#), but I assume that syntax declares a structure similar to a 2 dimensional STL vector. If that's true then I would assume that the functionality is reasonably the same. If that's true, then I would check … | |
Re: Why should a person learn win32 api? It's fun and it's a challenge. It gives you another tool in your tool box to use when needed. ___________________________________________ What things I can do when i have learnt it? Anything you want. Well, almost. Understand what's behind Visual Basic and why you … | |
Re: As the loop starts on line 2, what is the value of p and count? Where does the value of count come from? Have you called strtok() and assigned the return value to p before the loop on line 2 starts? | |
Re: Have you checked that the vector of vectors is filled with the default dot values? STL vectors are objects, not arrays. So when you pass a vector to a function it acts like an int or a char or a double. That means it can be passed either by value … | |
Re: In my opinion the Menu class should deal with menus. I would recommend you declare an Airline class to deal with things like searching for a Flight, adding/deleting a flight, etc. The Airline class should also be able to display a Flight, though that may be as simple as having … | |
Re: WaltP's response seems a bit harsh to me. The program posted does indeed demonstrate one way to accept input (though it doesn't look like it will appease the instructor given the comment in the instructions that the ASCII value for return key is 13, implying that input should accept all … | |
Re: What are you trying to do with find()? There is no decimal in the sample input. If numerical values are restricted to positive ints, as posted, there is no dash either. Read in an entire line at once using cin and use a stringstream object to break out the pieces … | |
Re: We can't see your corrected code, but why do you feel you have to send Head to print_circle() but not to add()? Since Head is declared with global scope on line 11 it can be used anywhere in the program and shouldn't need to be sent anywhere. That can be … | |
Re: Try not to use multiple variables with the same name within the same program. It's asking for trouble. The only exception might be a simple counting variable used within loops, but then make the variable local to the loop so you don't forget to reset the value to a default … | |
Re: The way to do this depends on what you know already. Using the substring function in the STL string class is one way to do it. Writing your own substring function is another way to do it (find the first char in the substring to find in the subsring to … | |
Re: FYI: the functionality you've declared for your list is more that of a double ended queue, or dequeue. Lists generally allow for random insertion of new nodes and don't restrict activity to both ends. | |
Re: let's say you have a board declared as as multidimensional array of char. If there isn't a ship in the cell the value stored in the cell is a space char. If there has been a hit there is an H. If there is a ship there then it has … | |
Re: >>in the interval [x,y] how many numbers have exactly 14 divisors 24 has 16 integer divisors: 24, 1, 12, 2, 8, 3, 6, 4 (and respective negative ints) 24 has 8 positive integer divisors 24 has 2 prime divisors: 2 and 3, assuming the definition of prime divisors is divisors … | |
Re: I would use a loop for each denomination of coin. I would subtract the value of each coin from the remainder each time through each loop and I would increment the number of each coin appropriately each time through a loop. I don't see how division or modulus will give … | |
Re: You might be surprised by the amount of grey hair at the casino's! (And 't aint all from stress of loosing neither!) | |
Re: Here's a rough schema that might work to evaluate a hand given your format. Cards with number 1-13 are clubs, 14-26 are diamonds, etc. So if all cardsnumbers are within 1-13 you have a flush in clubs, 1-26 you have a flush in spades, etc. If all cardnumbers are within … | |
Re: Recommend you search the site as this is a common problem to solve with C++. If you have any questions after doing the search, then start another thread given there is no continuity between the polynomial thread and the reverse polish logic other than you are the poster for both … | |
Re: If you don't declare a constructor the compiler will declare a default constructor for you. However, if you declare a constructor, then there will be no default constructor declared for you, unless you declare it for yourself. In your case your have declared a non-default constructor taking 6 ints as … | |
Re: First you need to know what those topics are. Then if you know how to manipulate arrays the code to do this becomes pretty straight forward. Post specific question about a specific problem with relevant code and/or error messages and you will likely get all the help you need to … | |
Re: I'd go the other way around. Create a char array of size 5----to hold four visible char, each will be digits, and a terminating null char. The null char will allow you create a string,that can then be converted into an int using any of several protocols. To get the … | |
Re: 0-29 is a label (string), not a value (int). Initialize the ints called Grade1,...,Grade4 to 0. Use a loop to input the grades. Use an input with a value of over 100 to stop input after an arbitrary number of inputs. You can either use an infinite loop and use … | |
Re: main() is a function, a somewhat specialized function, but a function, nonetheless. It has a return type, int, a name, main, and a list of arguments contained within ()s, just like any other function in C++. The two arguments for main() are an int, called argc, and an array of … | |
Re: Have you considered using a loop to request input into a given salary[ctr] as long as salary[ctr] equals zero? | |
Re: Assuming the OP doesn't know anything about sets or containers other than arrays and that there are 5 balls and 5 students then this becomes a learning situation for using loops, arrays, conditionals, flags and generating random values. Basicaly: Declare an array of 5 ints. Use rand() (and srand()) to … | |
Re: The size of your array can be handled with dynamic memory, as I demonstrated earlier, or with an array that will be big enough to suit your needs, as Salem demonstrated, or with a vector of vectors as Sky Diploma suggested. Those are your choices. If you don't know about … | |
Re: If you've got the time and drive to keep at it then consider stepping into the waters of graphics programming. Create code to visualize the nucleus of a helium atom, a sun with a planet spinning around it, simple molecules that spin and tumble or, a little more playfully, implement … | |
Re: [code]bool playAgain = true; //control outer loop bool notFound = true; //control inner loop int attempts = 0; //control inner loop char again; while(playAgain) { while (attempts less than 3 and notFound) { printf ("Input guess : "); scanf("%d", &usersGuess); if (usersGuess > random || usersGuess < random) attempts++; else … | |
Re: Run time errors are always the hardest to find. Learning how to view variable values as the program is running is one of the most useful techniques I can think of to be successful in this task. As I look at your code and the output you have presented it … | |
Re: >>So how do I continue reading in a new input and still get the names and scores from the file? Read the file line by line using getline. Look at the fist char of the line read in. If it's an '%' the line is an instruction so find the … | |
Re: Good of you to post only relevant code and relevant error messages, although in the future it would help if you correlate the line(s) referred to in the error message to the code posted, because the line numbers will likely be different. In this case I suspect the problem is … | |
Re: Beware of mixing calls to >> and getline() in the same program. The default termination character for getline() is the newline char. getline() will stop putting additional information into the target string whenever if finds the terminating char. getline() will remove the terminating char from the input stream. White space … | |
Re: How are you going to handle the leading numbers, like 1., 2., 3., etc., and the spaces that come after the period and the first letter of the name of the film? | |
Re: What question do you have. What you have posted seems reasonable enough. Does it do what you think it should? Do you the comparison of characters to be case sensitive (F is different from f) or not (F will count as f)? If the latter then you will want to … | |
Re: First be as precise in you question as you can. For example: If given the int 15287 I am supposed to arrange the digits in ascending order to get 12578 without using an array. How would I do that? Bubble sorts work on arrays. Can you use a list or … | |
Re: I think this will work. WARNING:code snippet not tested. [code] char ch; string lexeme = ""; //while a char is found while (fin >> ch) { //concatenate the char onto lexeme lexeme += ch; //get all the char until the next whitespace char or eof is found while(fin.get(ch)) { if(ch … | |
Re: The best way to get help with problems like this is to explain what answer you expected to get and what answer you actually got, in addition to relevant code. I'm going to guess that the output when you ran the program was something like 0/1 and junk output of … | |
Re: If the numerical input can be any floating point value, then you have a harder job. One way to try might be convert the floating point value to a string using a stringstream, find the decimal point and count how many digits are present to the right of the decimal … | |
Re: Seems like you're writing too much before testing. Write and debug no more than 1 function, or subroutine of a function, at a time. In your code main() calls all() which calls writeChar() which calls openFile2() which doesn't call anything, so nothing gets done. You should be able to do … |
The End.