1,608 Posted Topics

Member Avatar for Mander

Do yourself a favor, never write a whole program and then try to debug it. You'll just drive yourself crazy. Start like this: [code] #include <iostream> // includes iostream #include <fstream> // ellows the program to write and reed files #include <string> using namespace std; int main (); { return …

Member Avatar for Mander
0
342
Member Avatar for Jennifer84

To my knowledge, you can't do that in C/C++, at least not in standard C/C++. I'll be happy to learn along side you if I'm wrong.

Member Avatar for Jennifer84
0
108
Member Avatar for jimJohnson

[code] //basic main function int main() int height, width height = Get_Number(1); width = Get_Number(2); //Get_Number prototype int Get_Number(int x) sentinnel variable input variable use loop until user get's it right ask user for height if x == 1 else ask user for width accept input if input less than …

Member Avatar for Lerner
0
545
Member Avatar for crazywoods

The char type in C/C++ can be viewed as an int so this: char ch; cin >> ch; switch(ch) { case '~': //do something; break; } is the equivalent to this: char ch; cin >> ch; if(ch == '~') { //do something; } Each additional case in the switch statement …

Member Avatar for plgriffith
0
259
Member Avatar for c++noobie

>>As for the c_str() function, what exactly does it do? It returns a const char * which contains the same char in the same order as the original STL string. const char* isn't the same as char *, so you can't assign one to the other. You can however cast …

Member Avatar for c++noobie
0
2K
Member Avatar for kylcrow

There's a saying about C/C++ that goes something like: "There is no such thing as a bad string." That usually is trumpeted when input is tried as a numerical value and you want to validate it. That is, you should accept the numerical information input as a string and then …

Member Avatar for dougy83
0
109
Member Avatar for Code.n00b

One solution would be to add an else if and if start == -1 then change pump to something other than 1. Nothing should happen except the user prompts showing up until user enters a value for start at the cin >> start level. In line 18 the values of …

Member Avatar for WaltP
0
121
Member Avatar for afg_91320

A menu drive program frequently has a list of options for the user to choose from, typically by having the user enter a letter or a number to correspond to the activity in the list they want to do. The user's input is then frequently used in a switch statement …

Member Avatar for WaltP
0
95
Member Avatar for ngozinyeusi

To give you an idea of the reason you got the responses you've gotten here's a brief synopsis of the basic tools/concepts I'd use to try to do this. I'd start with a two dimensional array declared on the heap using dynamic memory and initalized to a default value. Then …

Member Avatar for Lerner
0
229
Member Avatar for CBarr

Line 14 is an else statement. Typically anything you want associated with an if/else if/else statement or a for loop body or a while loop body should be enclosed in {}, like in the snippet for the if and else if. If there isn't a set of {} associated with …

Member Avatar for CBarr
0
94
Member Avatar for dreamgirl
Re: Help

Functions can have have a return type of void and they can have void, meaning no parameters passed, but I've never heard of a void function before. Please be more specific about what you want/need. Any function can call any other publically accessable function, irrespective of what the return type …

Member Avatar for Lerner
0
86
Member Avatar for adnanius

for(int i=It1;i<=v1.end();i++) //can I affect the value of It1 to i ? I wouldn't equate It1 with an int. I think you may want something like this: vector<photon>::iterator It1=v1.begin(); for(int i = 0; It1 != v1.end(); It1++, i++) or maybe this is easier to understand: vector<photon>::iterator It1=v1.begin(); int i = …

Member Avatar for adnanius
0
112
Member Avatar for guitarrick

Input validation can be a challenge, depending how nitpicky you want to be. Since your input format is so specific I'd suggest a grind it out char by char analysis. Maybe something along this lines: [code] bool isValidDate(stringType input) { bool result = true; //ensure each placeholder in input is …

Member Avatar for Joatmon
0
160
Member Avatar for Jennifer84

Not if the substrings need to go into a rigid set of variables. You could declare an array/vector that could hold up to 6 strings and extract them out of the original string one at a time storing them in the array as you go. In the array they won't …

Member Avatar for Jennifer84
0
191
Member Avatar for Jennifer84

Go here: [url]http://www.cppreference.com[/url] Look for C++ Strings and go to that page. Look up find(), substr(), erase(), and anything else that might look useful. Use whatever combination of methods seem to work, say maybe a loop within which is a call to find followed by a call to substr() followed …

Member Avatar for Lerner
0
920
Member Avatar for Joatmon

Sounds like you're trying to delete some memory you already deleted, or that someone else deleted for you (like if you were using an STL container class to hold the number of links)

Member Avatar for Joatmon
0
118
Member Avatar for winky

The Node struct is correct. However, your use the btree class does have several problems. First: You don't need to scope operator in the following line, and those like it. void btree::preorderWalk( Node *root ); It's not actually an error according to my compiler, but it isn't necessary. This is …

Member Avatar for mitrmkar
0
124
Member Avatar for maverick786

First, I assume that num represents the number of nodes visited during the search process. If so, I'd assign num the value of zero inside the calling function and increment the value by one, outside of the if/else statements, each time the function is called. If num isn't assigned the …

Member Avatar for Lerner
0
112
Member Avatar for Trini89

The modulus operator is routinely used on variables of type int. If the amount of the difference is a type float or double then you could multiply the difference by one hundred and cast it to an int. Then you can use integer math, including the % and /= operators, …

Member Avatar for Lerner
0
95
Member Avatar for jer_stud56

streams to manipulate files come in three basic types (at least for us beginners): streams dedicated to reading from files--- ifstream, streams dedicated to writing to files--- ofstream, and streams that can either read from or write to files depending on what mode it's in---fstream. To use an ofstream you …

Member Avatar for mitrmkar
0
604
Member Avatar for atish00

// increment source string **p2; In some cases it can even be a typo!

Member Avatar for Dave Sinkula
0
139
Member Avatar for Spencicle

My rule of thumb is to use for loops if I have control over when the loop will stop---for example if I want it to work X times or if I want it loop while X < Y, etc, AND if the increment I want to make is the same …

Member Avatar for superjacent
0
1K
Member Avatar for sonygamer

I'd declare a function accepting an int and returning void. The stopping value would be when the int passed in is less than 10, since that would be Eigen digit If the int passed in wasn't the Eigen digit, then I'd declare an int called temp to pass to the …

Member Avatar for Lerner
0
336
Member Avatar for The Midnighter

There are several concerns with the code snippet you posted. First, don't use eof() in the while conditionals. Second, the if statements are superfluous. Third, the first time through the loop, current will always be placed in the file associated with fout1. That may or may not be appropriate, I …

Member Avatar for The Midnighter
0
190
Member Avatar for guitarrick

Depends I suppose on the list of wrong characters, and the type of string you're going to use, etc. A brute force char by char analysis of the string will always work of course, but you may be able to use find(), strtok(), etc too, depending on the situation.

Member Avatar for farag
0
103
Member Avatar for Ryuji5864

Welcome to Daniweb! Please use [ code ][ /code ] tags (with the spaces next to the square brackets) when posting code to this board to maintain the indentation you (hopefully) use when writing your code. The error message probably means that you should have a statement of some sort …

Member Avatar for Ryuji5864
0
175
Member Avatar for begyu

I'd attack this problem by creating a display() method for the Matrix class or overload the << for the Matrix class. This will allow you to see what the result of sum /= 5 is. I think the real problem is the need for an overloaded assignment operator for the …

Member Avatar for Lerner
0
137
Member Avatar for chocl8drop

[code] for (int compare = 0; compare < count - 1; compare++) { if (array[compare - 1] [/code] While the above code is syntactically correct it will produce a runtime error since compare - 1 will be -1 when compare is zero, and -1 is out of bounds for array …

Member Avatar for dougy83
0
127
Member Avatar for orangejuice2005

Here's a slightly different algorirhm. [code] Given: 1) a fixed maze with: a) defined room for mouse to start and b) defined room for placement of cheese and 2) each room has: a) a flag for being visited, and b) 4 sides which may either be a wall or a …

Member Avatar for Lerner
0
1K
Member Avatar for armanp

First welcome to Daniweb. Second, when posting code on Daniweb please enclose it in code tags to maintain the indentation you (hopefully) use in the code you write. Use of the tags is discussed in the watermark to the message box you type in before you start typing as well …

Member Avatar for Lerner
0
105
Member Avatar for orangejuice2005

You appeared to have too many loops and too many calls to push_back(). See if this works better. [code] Polynomial operator+(const Polynomial& p1, const Polynomial& p2) { Polynomial result; term r; vector<term>::const_iterator p1Current = p1.poly.begin(); vector<term>::const_iterator p1End = p1.poly.end(); vector<term>::const_iterator p2Current; vector<term>::const_iterator p2End = p2.poly.end(); for( ; p1Current != p1End; …

Member Avatar for Duoas
0
2K
Member Avatar for nezumi4

char list[size]; dataFile.write(reinterpret_cast<char *>(&list),size); You probably want to put something into list after you declare it and before you write it to file. If you must use the binary mode of read/write from file, then use the read() method to read from the file into the string. Otherwise, I'd encourage …

Member Avatar for Lerner
0
101
Member Avatar for sgw

Standard input in C++ is buffered (nonstandard methods are available to get unbufffered input if it's needed, but that can limit the portability of your program). This means when your program obtains data via the key board or from a file or from wherever else, the data is entered character …

Member Avatar for Narue
0
258
Member Avatar for nurulshidanoni

Do you mean you want the first row and column of numbers in the table will represent the labels of the row and column respectively? If so and the table is table of ints or a table of strings, then the labels can be incorprated into the table by hardcoding …

Member Avatar for Lerner
0
78
Member Avatar for ankit_the_hawk

Input the whole expression as a string using the getline() method appropriate for the style of string you are using. Then parse the input expression into tokens using a stringstream. First create the stringstream by using the input string as a parameter to the stringstream constructor. Then use the >> …

Member Avatar for TimeFractal
0
131
Member Avatar for thodragon

If you use code tags (you can read about them in the stickies above or in the blue watermarks that appear in the message box before you start typing/pasting in it) then the indentation you (hopefully) use in your code will be maintained in the post. It's a bit of …

Member Avatar for thodragon
0
137
Member Avatar for shadowfire36

I have stripped down your progam to highlight changes that seem appropriate and entered comments where changes made. [code] int main() { bool again = true; char letter; //change letter to type char, not type int while (again) { //displays menu cout << "What would you like to do?" << …

Member Avatar for WaltP
0
128
Member Avatar for olams

First, have main() return an int, not void. Second, in main() when you call eval() using polynomial a like this: a.eval(2.0); you are ignoring the return value of eval(). To see what the return value is you could print it to the screen directly like this: cout << a.eval(2.0) << …

Member Avatar for olams
0
152
Member Avatar for atish00

There are any number of ways to sort an array. Some of them are called bubble sort, qsort, sort(), merge sort, selection sort, etc. Each has their attractions and detractions. For arrays of relatively small size the bubble sort seems to be very popular with beginning programers because of the …

Member Avatar for Lerner
0
146
Member Avatar for inocntreper

the item inside the switch() parenthesis must resolve to an int. That means each case must resolve to an int. 'Ja' is not an int. In fact it isn't anything. 'J' is a char and char are interpreted as ints by the computer so that works. "Ja" is a string, …

Member Avatar for Lerner
0
101
Member Avatar for certem

Maybe I'm missing something here, but one of the hardest things for me is to remember the computer doesn't do things like I do. I always try to get the computer to do things the way I do when I should be taking advantage of the special characteristics of the …

Member Avatar for John A
0
245
Member Avatar for comwizz

The best approach would be to show how you have altered your original code. It should be something like this: [code] int main() { int i,no; //name and acc_type have no memory associated with them, so you can't use them yet. //char *name,*acc_type; //allocate some memory to name---say maybe static …

Member Avatar for Pranav Aggarwal
0
645
Member Avatar for dexter1984

You could use a boolean flag to control the loop. Ask for input wihin the loop body and evaluate the result. If the input is zero then change the value of the flag. If not, then do your calculations.

Member Avatar for JRM
0
203
Member Avatar for mauro21pl

You first need to decide what tools you have to solve the problem. I'd use C++ with classes to represent a Card and a Hand and I'd sort the Cards in a Hand as they are dealt rather than sort the hand after the deal, but it could be done …

Member Avatar for WaltP
0
93
Member Avatar for noodlneck

>>float maximum(float x, float y, float z); drop the semicolon at the end of this line. With the function maximum() being defined before main() you don't need a function declaration as well. So you can delete the following line: float maximum(float number1, float number2, float number3); // functional prototype

Member Avatar for noodlneck
0
333
Member Avatar for bis student

continue means go the start of the loop ignoring any remaining lines in the loop break means go to the end of the loop ignoring any further lines or iterations of the loop

Member Avatar for JRM
0
132
Member Avatar for starkman

First, don't use the return value of eof() to control loops. Intsted call the stream directly within the conditional. In this case it would be: [code] while (getline (eyetrack, line)) cout << line << endl; [/code] Then you can query eof() to determine if input stopped due to finding end …

Member Avatar for Lerner
0
637
Member Avatar for HowBil

>>How did it come to interpret it that way? "" is an empty literal string. The compiler is calling it a char pointer rather than a char array. >>while (cin.get() !="") get() is an overloaded istream method that can be used to get either a single char or a C …

Member Avatar for Lerner
0
223
Member Avatar for vanalex

To elaborate vijayan121s point; as I understand it, arrays of user declared type are constructed using the default constructor of the user defined type. If you don't declare a non-default constructor for your user defined type the compiler will declare a default constructor for you. However, if you declare a …

Member Avatar for rkavinash
0
112
Member Avatar for driplet

A little more restricted than global objects, but still worth considering in the right context, are class members declared with the keyword static as part of the declaration. These are variables that can be used by any instance of the class, but only by instances of that class. For example, …

Member Avatar for Ancient Dragon
0
118

The End.