Forum: C++ 4 Days Ago |
| Replies: 2 Views: 229 When mixing getline() and >> in the same program you have to account for the fact that >> leaves the terminating whitespace (new line char usually) in the input buffer. Then when getline() comes... |
Forum: C++ 4 Days Ago |
| Replies: 9 Views: 259 The most obvious possibility, but maybe the least likely, is that the prototype withdraw() post #3 line 1 and function call to withdraw, post #4 line 54 do not match with regard to number of... |
Forum: C++ 6 Days Ago |
| Replies: 9 Views: 246 Definition of template member funtions needs to be in the header file, not in the cpp file.
Where is Bank.h? From what is posted I can only guess at what's in Bank.
I hope Bank.h includes... |
Forum: C++ 6 Days Ago |
| Replies: 9 Views: 246 You might want to look into Run-Time Type Identification (RTTI). I got some pretty good hits searching RTTI on Google. A good reference book is hard to beat though.
You might be able to get by... |
Forum: C++ Oct 23rd, 2009 |
| Replies: 5 Views: 327 Notice the different placements of the curly brackets betweenn the code written by Clinton Portis and your code. He checks the value of counter within the while loop to start a new line if needed,... |
Forum: C++ Oct 18th, 2009 |
| Replies: 4 Views: 255 No need for AssignValue to be a friend function unless it is a requirement of the assignment.
How will AssignValue know how many digits to place before and after the decimal point? 123.456 ... |
Forum: C++ Oct 18th, 2009 |
| Replies: 4 Views: 245 If you know the first key then maybe something like this will work.
Encrypt:
while there are letters to encrypt
generate random letters until current key is generated
place a letter of message... |
Forum: C++ Oct 13th, 2009 |
| Replies: 3 Views: 291 First, I'm surprised the code compiles given that you declare StoArrayXYZ using a non-const int.
You should probably have the class methods defined in a file of the same name as the header file... |
Forum: C++ Oct 12th, 2009 |
| Replies: 3 Views: 285 Focus your code posting to just the pertinent part. sometimes it's hard to know where that is, but in your case it shouldn't be.
Sounds like a do/while loop using something like isdigit() might... |
Forum: C++ Oct 9th, 2009 |
| Replies: 6 Views: 294 How about including public functions read() and write(). Both should take an int parameter. Then you can call MyObject.read(n) and MyObject.write(n). I don't see how you can overload [] to both... |
Forum: C++ Oct 9th, 2009 |
| Replies: 6 Views: 294 have you tried syntax similar to this:
MyObject.bvec[n];
It should work as long as n is less than the size of bvec, which in the code provided would anything 0-9 inclusive. |
Forum: C++ Sep 30th, 2009 |
| Replies: 3 Views: 212 The best thing to do is get a reference book, preferably hardcopy, though there are some online resources as well. In general you use filestream objects to read and write to files as opposed to an... |
Forum: C++ Sep 29th, 2009 |
| Replies: 2 Views: 519 Declare a maze that will consist a 12 by 12 board represented internally by a 2D char array. The characters in the array will be # to indicate walls, space char to indicate available choices... |
Forum: C++ Sep 28th, 2009 |
| Replies: 6 Views: 591 Post #6:
line 12 should be int y;
line 15 should be DayOfYear(int day)
line 17 should be int dayOfMonth = y = day;
Line 23 should be expanded to contain 2 sections.
Section 1:
substract... |
Forum: C++ Sep 27th, 2009 |
| Replies: 6 Views: 591 Well, it should be y = day; but I've been guilty of that typo more than once.
I would:
//declare these variables within the class
static const int daysInMonth[12] = {31, 28, 31, 30, //etc... |
Forum: C++ Sep 16th, 2009 |
| Replies: 7 Views: 488 This:
string arrcon[5][35];
is basically a table of words/strings composed of 5 lines and 35 words/strings per line. The size of each word/string is indefinite. arrcon[1] is the second line of 35... |
Forum: C++ Sep 16th, 2009 |
| Replies: 19 Views: 615 >>I'd have to make functions or cases for each and every conversion like one for cm-m, cm-ft, etc. Is there any other way to do this?
Sometimes the buttons can be used for different purposes... |
Forum: C++ Sep 15th, 2009 |
| Replies: 4 Views: 717 In C++ there are multiple varieties of strings. C style strings are null terminated char arrays. dateStr and timeStr in post #4 are probably going to be used as null terminated char arrays. Null... |
Forum: C++ Jul 31st, 2009 |
| Replies: 7 Views: 325 Using the shuffle approach has the advantage of you being able to hardwire the possible numbers and use standard algorhithms (there is a function called random_shuffle() in the STL algorithm header)... |
Forum: C++ Jul 31st, 2009 |
| Replies: 7 Views: 325 Assuming maxrand is an int, or something that equates to an int, then the number returned by rand % maxrand should be between zero and maxrand - 1, inclusive. It will never generate maxrand per... |
Forum: C++ Jul 29th, 2009 |
| Replies: 5 Views: 468 I've never seen structs/class objects initialized using the {} syntax. To my knowledge that only works with arrays, though someone may prove I'm wrong on that. You can, and should, use the... |
Forum: C++ Jul 13th, 2009 |
| Replies: 8 Views: 602 Are you wedded to using strtok()? If not, use the '`' char as the delimeter of the parsing phase, whether the parsing is done initially or after first line read.
while(read in first line)
{
... |
Forum: C++ Jul 13th, 2009 |
| Replies: 10 Views: 455 char *strcat( char *str1, const char *str2 );
That's the prototype for strcat() from the online reference I usually refer to. I always thought str1 needed to be a null terminated char array and... |
Forum: C++ Jul 10th, 2009 |
| Replies: 8 Views: 277 How about using a sentinnel/flag? A little bit of a hassle to enter an additional keystroke, but it is completely portable, offers complete control without using magical combinations, etc.
bool... |
Forum: C++ Jul 9th, 2009 |
| Replies: 4 Views: 477 Can't tell out of context. Need more code. |
Forum: C++ Jul 9th, 2009 |
| Replies: 2 Views: 244 First, please learn how to use code tags when posting to this board. See the announcements at the top to board to learn how to do this.
Second, rand() in this line:
if (guess != rand())
... |
Forum: C++ Jun 27th, 2009 |
| Replies: 13 Views: 574 Sorry, all suggestions previously made by others |
Forum: C++ Jun 27th, 2009 |
| Replies: 3 Views: 498 This: while(in.eof()!= 1)
is probably why it is always shows the last object read in twice. You shouldn't use the return value of eof() to control performance of a loop body for that very reason.... |
Forum: C++ Jun 19th, 2009 |
| Replies: 28 Views: 1,049 One of the benefits about .h files is that you can include them in mulitple projects without having to retype the declaration each time. The linker will look up the definition/implementation each... |
Forum: C++ Jun 19th, 2009 |
| Replies: 28 Views: 1,049 Yes, it is okay to define some functions/methods in a header file but you don't want to go there yet as it will just get you more confused. If I haven't blown it myself the general rules would be... |
Forum: C++ Jun 19th, 2009 |
| Replies: 3 Views: 690 cin >> score[num_quizzes];
num_quizzes should never be used as an index for the array as it is out of bounds and will cause a run time error. If the above was an attempt to put all five scores... |
Forum: C++ May 26th, 2009 |
| Replies: 5 Views: 194 Using ignore() to clear the input buffer before each call to getline() when getline() is used in programs with other input methods is fine. The size of the first parameter sent to ignore() is... |
Forum: C++ May 26th, 2009 |
| Replies: 5 Views: 194 You have mixed use of >> and getline() in the same program. If you do that you need to be aware that >> will leave the terminating char in the input buffer which will be evaluted when the next call... |
Forum: C++ May 22nd, 2009 |
| Replies: 7 Views: 359 I find terminology used to describe 3D coding tend to be confusing---just like any new language when I start using it. To me, a point has no 3D representation visually. However, multiple points... |
Forum: C++ May 22nd, 2009 |
| Replies: 12 Views: 1,014 Another approach might be to display as you go. Here's some pseudocode to rough out how that might work:
1) declare variables needed---stream to read file and two int variables
2) use a while... |
Forum: C++ May 18th, 2009 |
| Replies: 7 Views: 740 Create a node using template syntax as per Stinomus' post above.
Create a list using template declarations for the List class which has all the variables and methods you want to use.
Create... |
Forum: C++ Apr 9th, 2009 |
| Replies: 12 Views: 873 Use a loop to count down:
cout <<"The program will be terminated in ";
for(int i = 5; i > 0; --i)
{
i << " seconds..." << endl;
Sleep(1000);
} |
Forum: C++ Apr 6th, 2009 |
| Replies: 8 Views: 339 Try outputting the value of sTr immediately before leaving the try block in the assignment operator. |
Forum: C++ Apr 6th, 2009 |
| Replies: 5 Views: 334 Start at the beginning. You know user will not be able to enter more than 20 numbers, but you don't know exactly how many until run time. One approach is to declare memory for 20 possible numbers... |
Forum: C++ Apr 6th, 2009 |
| Replies: 2 Views: 378 ios::ate is (primarily) for file writing, it truncates---overwrites previous file contents. ios::app appends to previous file contents.
What type is SSN? If its a STL string then you can do... |