1,608 Posted Topics

Member Avatar for breaies

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 …

Member Avatar for WaltP
0
252
Member Avatar for engineerchica

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 …

Member Avatar for engineerchica
0
463
Member Avatar for xnycdplx

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.

Member Avatar for Lerner
0
829
Member Avatar for lxXTaCoXxl

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 …

Member Avatar for lxXTaCoXxl
0
107
Member Avatar for vindom

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() …

Member Avatar for vindom
0
250
Member Avatar for danymota19

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 …

Member Avatar for Lerner
0
1K
Member Avatar for Jnk

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 …

Member Avatar for Jnk
0
457
Member Avatar for aashishsatya

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 …

Member Avatar for jaskij
0
690
Member Avatar for engineerchica

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 …

Member Avatar for engineerchica
0
176
Member Avatar for christian03

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 …

Member Avatar for Lerner
0
230
Member Avatar for denethor

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. …

Member Avatar for denethor
0
213
Member Avatar for franmaez_0716

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 …

Member Avatar for franmaez_0716
0
3K
Member Avatar for sota

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 …

Member Avatar for sota
0
467
Member Avatar for C++ programmer

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 …

Member Avatar for Ancient Dragon
0
142
Member Avatar for daldrome

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?

Member Avatar for deceptikon
0
2K
Member Avatar for gdubz

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 …

Member Avatar for Lerner
0
137
Member Avatar for avenger123321

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 …

Member Avatar for avenger123321
0
359
Member Avatar for sodha125

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 …

Member Avatar for KasmIR
0
202
Member Avatar for lmytilin

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 …

Member Avatar for Lerner
0
180
Member Avatar for jigglymig

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 …

Member Avatar for Lerner
0
108
Member Avatar for surferxo3

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 …

Member Avatar for Lerner
0
234
Member Avatar for venky019

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 …

Member Avatar for Lerner
0
225
Member Avatar for fishsticks1907

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.

Member Avatar for Lerner
0
105
Member Avatar for myrongainz

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 …

Member Avatar for Lerner
0
2K
Member Avatar for mikeshadow

>>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 …

Member Avatar for mikeshadow
0
506
Member Avatar for LacyMacy

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 …

Member Avatar for Lerner
0
206
Member Avatar for hsayid

You might be surprised by the amount of grey hair at the casino's! (And 't aint all from stress of loosing neither!)

Member Avatar for studentba065
0
6K
Member Avatar for bluewhale628

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 …

Member Avatar for Lerner
0
589
Member Avatar for Raymond10

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 …

Member Avatar for Raymond10
1
137
Member Avatar for Kunal0

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 …

Member Avatar for ravenous
0
288
Member Avatar for programing

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 …

Member Avatar for adityatandon
0
119
Member Avatar for PeTo.

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 …

Member Avatar for adityatandon
0
2K
Member Avatar for emaellie

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 …

Member Avatar for adityatandon
0
1K
Member Avatar for Srinivas0

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 …

Member Avatar for Srinivas0
0
189
Member Avatar for Srinivas0

Have you considered using a loop to request input into a given salary[ctr] as long as salary[ctr] equals zero?

Member Avatar for Srinivas0
1
542
Member Avatar for burcinerek

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 …

Member Avatar for vijayan121
0
289
Member Avatar for unk45

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 …

Member Avatar for Rabia_Akhlaq
0
303
Member Avatar for kbar1

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 …

Member Avatar for mike_2000_17
0
161
Member Avatar for Fotis_13

[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 …

Member Avatar for Lerner
0
2K
Member Avatar for Halogen1

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 …

Member Avatar for Halogen1
0
504
Member Avatar for cppluvr

>>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 …

Member Avatar for Lerner
0
226
Member Avatar for MugANDGlass

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 …

Member Avatar for Lerner
0
231
Member Avatar for MugANDGlass

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 …

Member Avatar for Lerner
0
157
Member Avatar for Semeno

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?

Member Avatar for NathanOliver
0
265
Member Avatar for ConfusedLearner

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 …

Member Avatar for bboy_fresh
0
274
Member Avatar for easterbunny

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 …

Member Avatar for easterbunny
0
2K
Member Avatar for demroth

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 …

Member Avatar for demroth
0
3K
Member Avatar for Desh2350

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 …

Member Avatar for Schol-R-LEA
0
4K
Member Avatar for Assassin7893

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 …

Member Avatar for Assassin7893
0
865
Member Avatar for jackmaverick1

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 …

Member Avatar for Schol-R-LEA
0
351

The End.