1,608 Posted Topics

Member Avatar for Thew

You could use a struct, a map, and maybe even STL pair class, to do something similar, but you can't do it with strings, unless the version information is a single char only.

Member Avatar for Lerner
0
128
Member Avatar for darussalaam

The algorithym is the same as if you were doing it with pencil and paper. Break it down into smaller and smaller pieces, then rebuild it. [code] int i, m; double y, x, b, a, first, second, third; //intermediate calculations to get first, second, and third go here //then add …

Member Avatar for darussalaam
0
77
Member Avatar for k2k
Member Avatar for flash121

Since you're using strtok() to separate the words, you're probably using a null terminated char array (C style string) as the original string and not using a STL string class object to hold the original string. If that's correct then instead of using the == operator to compare two C …

Member Avatar for Narue
0
219
Member Avatar for xs.usman

Multidimensional arrays are concepts designed to make the job/life of the programmer easier as the compiler may well convert the multidimensional array into a standard, single dimensional array. Multidimensional arrays are useful when data is thought of as being in tabular form such as seen in a spread sheet or …

Member Avatar for WaltP
0
681
Member Avatar for anallan

The erase() method of the STL class is overloaded to accept several different parameters. One version allows you to delete a single char at a specific address using an iterator to specify the address. One version allows you to erase a range of characters from the string using two iterators, …

Member Avatar for anallan
0
671
Member Avatar for tootypegs

There's only 1 cout in the snippet posted, but it's going to repeat the value of byte_1 as an int 532 * 32 times. Since you are hardcoding the byte names eliminate the inner loop and change all the buff[i][x] where i is the i from the outer loop and …

Member Avatar for VernonDozier
0
300
Member Avatar for #include<DAN.h>

to "clear" the char array if it is used to hold strings you only need to assign the null char to index 0. Note that '\0', \0, and 0 are all ways of indicating null char but "\0" isn't anything really. To put a null char in each index zero …

Member Avatar for Duoas
0
2K
Member Avatar for FoX_

To my knowledge the only requirement for a binary tree is that each node has one parent and two children, or one root and two leaves if you want to use that analagy (the only exception is the first node entered, which has no parent/root). You can set it up …

Member Avatar for VernonDozier
0
156
Member Avatar for thetechguy

As another solution you can avoid initializing the array elements and assign elements as needed instead. This seems to work for me at least. [code] #include <iostream> using namespace std; int main() { int i, j; char board[19][19]; //assign all elements ',' for(i = 0; i < 19; ++i) for(j …

Member Avatar for thetechguy
0
734
Member Avatar for raniajay

First, remember to post code surrounded by code tags to retain indentation to make the code easier to read. Assuming you want the peak of the triangle centered over the base then I would would calculate the numbers and put them into a container printing the container once all calcualtions …

Member Avatar for Jishnu
0
158
Member Avatar for mcham
Member Avatar for Lerner
0
112
Member Avatar for VanithaGopi

Thinking things through the best you can, frequently pencil and paper help a lot, before writing code will be very helpful. For example, you may want to to declare the bookstore as a collection of holdings and transactions. Each holding has a book and an inventory amount. Each transaction has …

Member Avatar for Lerner
0
81
Member Avatar for bis student

I thought this was initialization: int num[] = {1, 2, 3, 4}; and this: [code] int num[4]; for(int i = 0; i < 4; i++i) num[i] = i; [/code] represented serial assignment. Furthermore I think that either the instructor, the OP, or I (and I don't think it's me this …

Member Avatar for invisal
0
4K
Member Avatar for zoner7

The standard says that you should be using namspaces, that the iostream header file is located in namespace std, and that the iostream header file should be included as iostream not as iostream.h. The technical differences between iostream and iostream.h header files are so minute that probably less than 10 …

Member Avatar for Lerner
0
89
Member Avatar for Max_Payne

To me you appear to be trying to draw a collection of '.' to the console (or page or grid or even a file---the latter so you could print it on paper if you wanted). However, at the moment Point.draw() and Linea.draw() just output a single '.' at the current …

Member Avatar for Max_Payne
0
587
Member Avatar for Deadvacahead

Basically it sounds like you want to eliminate the last line of the file but not before you place an asterix before the correct answer. Correct? If so, then there are several possible approaches based on the exact format of the file. If each question section in the file consists …

Member Avatar for n.aggel
0
158
Member Avatar for Max_Payne

cstring replaces string.h which is where a lot of the standard functions to manipulate C style strings (null terminated char array) are located. string is the header for the STL string class and it contains the functions to manipulate STL string objects.

Member Avatar for dubeyprateek
0
218
Member Avatar for nicz888

Use an istringstream to parse the line into words delimited by whitespace. I suppose you could use strok() or similar protocol as well if you wanted. Here's one version using STL strings as opposed to C style strings. WARNING: code snippets posted below not tested [code] string inputString = "This …

Member Avatar for neosomosis
0
126
Member Avatar for Nbkrooney

It's an imperfect world we live in. If the name of achievement field can be of variable length and have variable amount of whitespace and you can't restrcture the file by including a delimiting char of some sort, then one approach I can think of is to view each line …

Member Avatar for Lerner
0
165
Member Avatar for Symbolite

One of the things functions can do is call other functions. You've already demostrated that by calling getValues(), findLow(), etc from within the function called main(). If you aren't able to change the function prototype/definition, then this fact should be able to help you devise a flow to the program …

Member Avatar for Lerner
0
96
Member Avatar for Jishnu

For what it's worth this reference: [url]www.cppreference.com[/url] indicates back() returns a reference to the last object. You can consult the standards to determine the answer if you wish. It is my understanding that end() returns an iterator to one past the last object in the container, not an iterator to …

Member Avatar for Jishnu
0
120
Member Avatar for tamlo
Re: C++

If I gave you a pencil and paper and then I gave you 12 numbers that you had to find the average of, how would you do it? I suspect you would add each number to a running total to accumulate a total and once you had the total accumulation …

Member Avatar for Lerner
0
163
Member Avatar for Dean_X

Your code is almost impossible to read due to poor formatting. Learning how to format with consistent and appropriate indentation will save you lots of time trying to debug and make it easier for others trying to help or trying to maintain your code. I don't see where you declare …

Member Avatar for WaltP
0
178
Member Avatar for Jakiro

Visualize each number and each operator in the input string to be a token. Then, if each token is separated from the next by a space you can use >> to get each token into separate strings. If ()s are allowed, then typically they aren't separated from the numerical input …

Member Avatar for iamthwee
0
143
Member Avatar for Underdog67

With this file format: 1234 Samuel Spade 15.5 2 H the name field will always include a space, between the first and last name. Using get() will stop input at the space. You could try using getline(), but that seems too complicated since there is no single number of input …

Member Avatar for iamthwee
0
117
Member Avatar for k2k

The code as written accepts keyboard input. If lines 17 and 18 are uncommented and line 19 commented out then you can use the same code to obtain input by reading from files that you used with keyboard input. Otherwise, it's a loop that obtains input and passes that and …

Member Avatar for Lerner
0
99
Member Avatar for mattp123

Does your code compile? Does it run as you expect it to for both routine and predictable special cases, if there are any? If so then the code is probably correct. If not, then isolate the part(s) that are causing the problem and try to get it to compile, run …

Member Avatar for Lerner
0
81
Member Avatar for __vmware__

Do you need the else statement there? The way you currently have it set up if l->data != value the first time through the loop, the loop will stop, and you will never advance to l->next. If l->data == value the first time through the loop you will never get …

Member Avatar for __vmware__
1
109
Member Avatar for danbellinger1

Suspect it has to do with these two lines: 1) bool checkRows ( int theSquare[][4], const int numRows, const int magicValue ); 2) checkRows ( theSquare, numRows, magicValue ); Line one says checkRows is expecting a 2 dimensional array of type int with 4, and exactly 4 columns in it. …

Member Avatar for Lerner
0
171
Member Avatar for balla4eva33
Re: Max

Post deleted, didn't check my internal delay to follow up on posts posted while I was writing mine.

Member Avatar for balla4eva33
0
118
Member Avatar for Ccrobinson001

Try this program. It should print input from file to screen. [code] #include <iostream> #include <fstream> #include <string> using namespace std; int main() { char gender; int answers[10]; string name; int i; ifstream fin("clients.txt") if(!fin) { cout << "unable to open file" << endl; exit(1); } while(fin >> gender) //if …

Member Avatar for Ancient Dragon
0
228
Member Avatar for Nidaa87

Your formatting leaves a lot to be desired. [code] void linkedList :: create() { node *newl = NULL; node *end = newl; int data; head = NULL; cout << "\nCreate the List. Press <ENTER> after each entry\n"; for(int i = 0; i <= 5; i++) { cout << "Enter a …

Member Avatar for Salem
0
99
Member Avatar for zandiago

3. Remove these letters from the alphabet: declare a string containing all the letters of the alphabet. loop through string2 and compare each letter in it with each letter in the alphabet string. Each time you find a letter from string2 in the alphabet string replace it with an asterix. …

Member Avatar for zandiago
0
978
Member Avatar for tarekkkkk

1) correct my faults. Sorry too big a task. Specific questions are more likely to be answered. However, for starters I'll start here: A) Posting code this board is a little tricky. You need to use code tags to keep the indentation I hope you used when writing the code. …

Member Avatar for tarekkkkk
0
126
Member Avatar for scorpio40330

Do you know about user defined types like structs or classes? Do you know about arrays? Do you know about streams that write to and read from files? Do you know what pseudocode is? Do you know how to request user input and accept it into variables? Do you know …

Member Avatar for ithelp
0
103
Member Avatar for balla4eva33

If you want to hand roll it yourself you could try something along these lines for the + operator body: [code] totalDays = dayInMonth + days; if totalDays <= numDaysInMonth(month, year) dayInMonth = totalDays; else while totalDays > numDaysInMonth(month, year) totalDays -= numDaysInMonth(month, year); ++month; if(month == 13) month = …

Member Avatar for balla4eva33
0
120
Member Avatar for poopsy

The way it should be done depends on you. Do you know about arrays, multidimensional arrays, functions, how to determine if a move results in a win using pencil and paper, etc.? If you know about these things then write down on paper instructions on how to set up and …

Member Avatar for Lerner
0
99
Member Avatar for knowledgelover

The range from -1 to 1 is 2. So get random numbers from 0-2 (rand() % 3 should do that), then subtract 1 from that number. The results should be -1, 0 or 1. Now if you want decimal values, not integer values, ranging from -1 to 1, then a …

Member Avatar for Killer_Typo
0
461
Member Avatar for Oreynid

accept input as a string---no error checking needed as string type is always valid check first char of string to see if it's alphabetical char, if not get new string if first char of string is alphabetical char convert it to upper case as needed. can clear the input string …

Member Avatar for Salem
0
10K
Member Avatar for bigt2008

include the iostream and fstream header files at the top of the program. You can use the ifstream object you declared, inFile, just like you would cin.

Member Avatar for Lerner
0
90
Member Avatar for ENG ISE student

The file better set up so each field is entered in the in the same order. Otherwise you're SOL (usually). Since you know how the file is set up, you know which field comes first, which comes second, etc.

Member Avatar for ENG ISE student
0
114
Member Avatar for Slate2006

xyz should be an array of ClassList objects each of which has an array of test results in it. Each ClassList object stands for a single student. You want to calculate the average test result for each student withing xyz. So you need a nested loop, the outer one to …

Member Avatar for Lerner
0
95
Member Avatar for Villanmac

Use a loop within a loop----a process often called nested loops. The outer loop controls the row and the inner loop controls the column. The body of the inner loop is where the output statement occurs.

Member Avatar for Lerner
0
125
Member Avatar for ricnyx

I'd suggest using a single ifstream clearing and closing at the end of each file and reopening with the next file in sequence. [code] ifstream fin("x.txt") while fin >> name fin >> amount cout << name << ' ' << amount << ' ' sum += amount fin.clear() fin.close() fin.open("xx.txt") …

Member Avatar for ricnyx
0
132
Member Avatar for phvan

1) don't use eof() to control the loop. 2) Read the file line by line using getline(), not >>. 3) Once the line is read in parse by the following cycle: look for first space, then look for next digit, then ignore the rest It's not the most straightforward line …

Member Avatar for WaltP
0
126
Member Avatar for BlackNinja

if arrayname[2] is a C style string then atox would be doable. if arrayname[2] is an STL string then a C style string could be obtained from an STL string using the c_str() string class method. Alternatively, you could try Ancient Dragons recommendation and try using a stringstream object to …

Member Avatar for BlackNinja
0
135
Member Avatar for nicz888

no need to cast all the literal char value to an int. Evaluate each section of the conditional starting on line 63 individually. All options in the conditional must be true to continue the loop. If input == any of the desired char then the loop should stop. Therefore I …

Member Avatar for Lerner
0
183
Member Avatar for cgraves

Read about using code tags when posting code to this board or risk restricting the number of responses from quality responders. return main(); //OUCH! Read up on loops and use an int called flag to control it after telling the user they could enter 3 to stop the game.

Member Avatar for WaltP
0
112
Member Avatar for picklesandmayo

Do you even need a container (array, vector, list, whatever) for this project? Just a recursive function with single numerical variable should do it I think. The variable would need a default value to discontinue input and spit the variable from each function call return value back out to the …

Member Avatar for Salem
0
191

The End.