1,362 Posted Topics
Re: Looking at AD's version above, line 25 has a common typographic error (hey, we all do this from time to time!) Line 19 could be improved by setting the loop limit as [inlinecode]for( i = 3; i < n/2 +1; i += 2 )[/inlinecode]. This will save doing tests for … | |
Re: Would you care to fully describe your problem? Please see the link at the top of this forum page: [url]http://www.daniweb.com/forums/thread78223.html[/url] | |
Re: Your logic continues testing all letters, and when the loop ends all you know is the state of the final comparison (first and last letters.) When a mismatch is encountered, you should immediately exit the loop. Or, initially set the RESULT to true, assuming a palindrome. If a mismatch is … | |
Re: Did you not see the answers when you asked this same question yesterday? | |
Re: Are your variables: day_count,month_count,year_count doubles or ints? The function is expecting references to doubles, but by their names I'd expect the actual arguments to be declared as integers. As Narue said, a full example of the problem would be helpful. Val | |
Re: In your array declaration [inlinecode]stackArray = new string[value]; [/inlinecode], you are trying to use a string (value) where you need a constant integer. That is, there should be a number inside the square brackets. It's not clear here, but if stackVal is also an int, again, you cannot assign a … | |
Re: Look at your variables in the if statement [inlinecode] if (transCustNum == custNum) [/inlinecode] Are they the same as what you are reading into from the files? Then, you are reading in one customer record and possibly many transactions records. This can put you out of transaction data before running … | |
Re: AD - no disrespect, but I don't want you programming for my bank! 8-) float is not a good choice for dealing with money amounts - the problems of (lack of) precision show up very easily. Even using doubles can lose pennies quickly the more you manipulate the numbers. That … | |
Re: Welcome. You'll find there's a C++ forum in the Software Development section, which is a better place for this question. You were on the right track with the ignore( ) function, but you used it improperly. Your goal with that is to remove any trailing spaces and the newline after … | |
Re: It appears that GCC is compiling your program thinking it's a C program. If you can set DJGPP to call the compiler as "g++" instead of "gcc", it will compile and run correctly. I'm not very conversant in DJGPP's configuration settings, nor and I clear why GCC is not correctly … | |
Re: Not reading the error messages from your compiler? A little more explanation of where you feel you are having a problem will help us to help you. Val | |
Re: [QUOTE=EnderX;465587]1 + 4, maybe?[/QUOTE] Math like this? [url]http://www.youtube.com/watch?v=Bfq5kju627c[/url] | |
Re: Well, consider your line: [code] else if((AMPM == "AM" || AMPM == "am") && (hours >= 10 || hours <= 11)) [/code] the Boolean operator should be AND not OR, same as you did in the 0 to 9am block. or you could simple test for equality to 10 OR … | |
Re: You've answered your question. It is a limitation of the precision of the long double - 15 digits in this case. I'm betting you're using M$ Visual C++ - it limits long double to 8 bytes, same as a plain ole double. If you ran the same code in other … | |
| |
Re: That is a default value for z. Thus, you can call the function with just two arguments, and z will be assigned the value 1. If a third argument is passed to the function, z will be assigned that value. Val | |
Re: Problem 1 - your are taking the input before prompting the user. Restructure your loop as: [code] cout << "Enter a string at least 8 chrs long: "; while (cin>>word) { len = word.length(); count++; word1 = word.substr(0,3); //rest of processing here cout << "Enter a string at least 8 … | |
Re: Dells have a reputation for being finicky about memory. You might try the Dell user forums for specific advice on your model. [url]http://www.dellcommunity.com/supportforums/board?board.id=insp_general[/url] Val | |
Re: Really, all you do to change a struct to a class is change the keyword. The only significant difference between a class and a struct is the default access level - class defaults to private, struct to public. Otherwise, they are the (99.999%) the same. | |
Re: Since the the errors refer to main.cpp, how about post that? | |
Re: I find that C++ textbooks in general completely ignore the topic of command line arguments, so I won't tell you to look in the book. Here are a few links that may help you to understand how to do this: [url]http://www.cprogramming.com/tutorial/lesson14.html[/url] [url]http://malun1.mala.bc.ca:8080/~wesselsd/csci161/notes/args.html[/url] The short version is that argv[] is an … | |
Re: Your problem lies in the intermediate variables you use in the whichfib( ) function: [code] long double whichfib (int num) { int count=2, newnum1, newnum2, newnum; long double fnum; [/code] Your use of long double is good for dealing with the large values that will result. You should also use … | |
Re: Structs do nothing to replace functions or arrays. Rather, structs make it easier to use functions and arrays when you have multiple pieces of information, possibly of different data types, that relate to a single object. Using your example, if you did not have structs, you would need three separate … | |
Re: Besides making the code more readable, I think you need to clarify what you mean (or what the assignment means) by the "average of the sum of the squares/cubes". What your code appears to be doing, is for each number 5 through 49, you are adding the squares of each … | |
Re: A major problem is how you are reading in data and controlling the loop. You read in a first and last name, then first off in your loop read first and last name again. So your input is out of sync with the actual data. When using eof( ) to … | |
Re: For problems 1 and 3, look at what you can do with integer division and modulus operations ( / and % ). #3 is actually the easier problem, if all you have to do is display the result. For the problem 2, are the input dates also given as year, … | |
Re: Yes. Generally speaking, any place you can have a single statement, you can use multiple statements enclosed in curly braces { } | |
Re: Oh, there's the problem. It should be: H C++ is a case sensitive language. (sorry, couldn't resist. too much time spent on usenet. Really, tom, please post the full code file and problem description.) | |
Re: You've pretty much answered your first question - the >> and << operators are shifting the bits of the initial value of x. In binary, the byte that stores decimal 5 is 0000 0101. Shift that left two place, you get 0001 0100, which is 20. This new value is … | |
Re: Parthiban's suggestion to pass the address of each character of number2 [code] value=atoi(&number2[x]); [/code] is not quite going to do what it appears you think the atoi() function is doing for you. atoi( ) give the integer value of the "string" pointed to by the char*. So, if number2 holds … | |
Re: Your array based solution is limiting in that you have set the array size to the number of values to display. What about a purely iterative solution, that does not need the excess memory, and is not logically limited in the number of values to display? [code] #include <iostream> using … | |
Re: A better design is to have the prime( ) function only return the 0 or 1 indicating primeness. Let main( ) be responsible for the actual printing of the number and * if appropriate. Your for loop is only printing the values that are prime. A little modification will fix … | |
Re: Yes, in general mixing sizes is ok, as long as pairs of modules are same sized. Having different sizes in the two banks may have an impact on dual channel usage, I can't speak to that particular aspect. Val | |
Re: MS Visual C++ 2005 Express free download at: [url]http://msdn2.microsoft.com/en-us/express/aa700735.aspx[/url] | |
Re: As written, your variable num_tri is controlling the size of the triangle, not the number of them. To do what you intend to do, the outer loop of draw_tri() should control the number of triangles (based on num_tri), then you need a set of nested loops in there that does … | |
Re: It may help to draw a picture of the data layout. [code] (index) 0 1 2 3 4 5 6 EmpID array | 12345 | 93948 | 87654 | 34564 | 43210 | 000111 | 007 | hours | | | 12.0 | | | | | rate | | … | |
Re: Also, your main loop control is a bit off. [code=c++] do { //show the menu cin >> userChoice; if ((userChoice>5||userChoice<1)) cout << "Not a valid choice try again: " << endl ; cin >> userChoice ; system("pause"); // I'm not gonna comment on how annoying this is! system("cls"); //Switch for … | |
Re: Let's start with the easy thing - why does this function return anything, and more importantly, your two return statements at the end will not do what you may think you're doing. Only the first return statement will execute, because once it does, you leave the function and the second … | |
Re: Nichito is right about lines 57 & 58 - they have no place in this program, they do nothing useful other than cause it to end before displaying your results. His revision to the calc function body does not change anything, just compresses three lines into one. Saves a couple … | |
Re: You can use >> operator to get the row/column values as ints, then read the data as individual chars [code] inFile >> rows >> columns; infile.ignore( 10, '\n'); //ignores up to 10 characters, or until newline //or infile.ws( ); //eats up the whitespace [/code] Then begin to read your data … | |
Re: What does the error message tell you? The answer you need is probably right there in the message. At least, look at the line the error message points you to, and carefully examine what your code is doing, versus what you think it's doing. | |
Re: Or, to avoid having to reset year to EOF each time, [code] do{ cout << "Enter a year: "; cin >> year; if( cin.eof( ) ) break; // rest of program here [/code] And similarly, the loop test can be written as [code] }while ( !cin.eof( ) ); [/code] | |
Re: As to the final bit always stating 7 days exercised, it's because you've made one of those typo errors we all tend to make from time to time. [code] if (counter = limit) cout << "The number of days excercised is " << counter << endl; [/code] You are assigning … | |
Re: Your getChoice( ) function gets user input, but does not pass it back to main( ). [code] cout << "\nPlease enter number for your choice: "; cin >> x; return x; //add this so the choice gets sent back to main( ) } [/code] Val | |
Re: From the problem description, it seems you should be pretty well into the course by now - loops and functions are requirements. That last paragraph give you quite a bit of information on how you ought to structure the program. The two functions are really quite simple, doing some comparisons … | |
Re: Assuming you understand how to write a recursive function, you need to establish what the base case is for this problem - when a parameter for the current term passed in is equal to the upper limit (10 in this case, but best also passed as a parameter for flexibility … | |
Re: What does terrestrial radio (versus satellite or internet delivered content) have to do with the matter? The copyright holders who license their material to the broadcasters (any type) expect the same personal use/commercial use protections and royalties. Val | |
Re: In real rodeo, he'd be a champ. He rode it for way more than 8 seconds! Val | |
Re: I don't think there's any "random numbers" being stored. Keep in mind that the array num[] does not get cleared out every time you read in a new string. It simply get overwritten from the 0 position for as many characters (including the terminating NULL) as needed. So, if on … |
The End.