1,608 Posted Topics
Re: if you wish to use >> to read the file, which is okay, then use this scheme: [code] string dayName double income //read one full line of file each time through the loop while(fin >> dayName) fin >> income [/code] | |
Re: You are displaying the screen with cout rather than writing to file with a user declared stream object. You are only outputting a single Product, not a group of Prtoducts. There are other syntax errors in the code as well, but these are the big ones I see in the … | |
![]() | Re: Look up the concept of nested loops in your reference material. It means a loop within a loop, and is a commonly used technique so there shouldn't be any problem finding a number of references. Then post code and specific questions about the code, error messages, etc, as necessary. ![]() |
Re: The first thing to do is to forget about the compiler for a while. Use a pencil and paper and try to work some things out. For example : What information is contained in the file about each client and how might you represent that using data types? What containers … | |
Re: Use cout to put the column lables you want between the second and third loop. Then format the output statement in the third loop so the output lines up under the appropriate label. | |
Re: I think this will work CPoint** points; make points a pointer to an array of pointers of type Cpoint*: points = new CPoint*[200]; each points[i] in points is a pointer to type CPoint so now you can call member functions using the -> points[i]->Move(); if that's what you really want … | |
Re: Beware that neither iostream.h nor conio.h are standard and therefore may not be available with all compilers. Likewise, recommending void main() on this board is even more likely to earn a reprimand than recommending nonstandard headers. main() should return an int, for a number of reasons. NB: Salem types too … | |
Re: Options: 1)Drop the validation routine until you get the program flow working, then come back and add it later. If it turns out the validation scheme isn't working, and I think that's the problem, then you'll know where to look and be able to ask a better question. 2) Place … | |
Re: I guess there are almost as many ways to learn computer programming as there are computer programmers. A couple of the contrasting styles include taking advantage of standard, already developed material vs reinventing each standard, well developed material in the name of education and understanding. If you're a fan of … | |
Re: >>That's generating actual objects called User1 and User2. What you want to do is typedef them But why does he want two user defined types with exactly the same innards? Why not two objects/variables of a single type? | |
Re: Sometimes when English isn't your native language it is even more difficult to explain what you want to do than it is for us native English speakers. To use multidiminsional arrays you can do something like this: int array[2][2]; which declares a variable on the stack with enough memory for … | |
Re: to convert the char representation of an int into an int you could do this: char x = '4'; int y = x - '0'; where the second line means assign the difference of the ASCII (or other char set) value of zero from the ASCII (or other char set) … | |
Re: Please use code tags when posting code to this board. You need to do multiple comparison's like this: if(choice == 'B' || choice == 'b') The three instances of that error is the only thing I see when looking quickly over your code. | |
Re: Here's a good online reference of standard functions used in both C and C++. You can use it for future reference and confirm the following. To use getline() with C style strings you need an istream object like cin or an ifstream object. You also need a C style string … | |
Re: [url]http://www.cppreference.com/stdstring/strstr.html[/url] You could look at this site to see if it's an example of what you are trying to do. There is a convenient conversion from string to C style string if there isn't a similar method built into the string class. ![]() | |
Re: To be standard drop the .h after iostream. The iostream header file is different from the iostream.h header, though functionally the are the same (the purists, specialists, experts may be aware of some subtle differences, but for us mere mortals they function the same). iostream, however, is the standard at … | |
Re: >>is there a way to make it read the values based on whitespace or something? There are all sorts of search/reading/parsing routines that can be used based on each individual search criteria. Let's say that each line has a minimimum of 6 substrings all separated from one another by spaces. … | |
Re: Depending on restrictions there is a function in the algorithm header file of the standard template library that will "automagically" shuffle a given group of items. However, that would take the fun and learning experience out of implementing the routine on your own. | |
Re: Post your current code or try printing out the values of S.pop() and Q.frontQueue() to screen to be sure you are getting the values you expect when you run a test program. | |
Re: What language/environment are you trying to work in (standard C/C++, Windows, Mac, C#, Delphi, other???). If it's anything besides C/++, Windows, Linux, or other C/C++ related specialty environments then there may be a better forum to ask these questions in. If it's Windows/Linux then the number of respondents familiar/comfortable with … | |
Re: If mode is the most frequently occuring number then find the frequency of the first number in the array. Since it's the most frequent value you've found so far it must be the most frequent at the moment. Then find the frequency of the second number in the array and … | |
Re: You mean something like this: [code] if ( sections == 1) //first class reqeusted { if(firstClass < 4)//implies there's only 4 first class seats available on this flight ++firstClass; //assign a seat in first class } [/code] | |
Re: Maybe this syntax will allow for nice looking columns. char space = ' '; char bar = '|'; //Header line: cout << space << space << 1 << space << 2 << space << 3 << space << 4 << endl; //line 2: cout << 1 << bar << grid[0][0] … | |
Re: open the file in textBox1 to read the text in the file // stumpted read text into a string or char variable // stumpted Which is why I would recommend you learn about standard C/C++ before trying to do nonstandard stuff like Windows, unless this is part of a class … | |
Re: //intialises x //intialises y Nope those are declarations. The value of x and y at this point is random junk. This would be a declaration and initialization: int x = 0; _________________________ //intialises from zero to 10 Nope. That statement validates that x is has value of 0 to 9 … | |
Re: >>any help or ideas is greatly appreciated Don't blindly copy and paste and expect the code to work. It sends a pretty loud message, that most people don't want to hear. If you want to use functions, then use them, but don't just slap into your program somewhere. For now, … | |
Re: The x in Narue's code is an arbritrary name for the index used in referencing each element of the array. She could have used sassafrass or i or y or any other variable name she wanted. To display the values within an array you can loop through them one by … | |
Re: Functions, like variables, need to be declared before being used. They can be declared from within other functions, though most frequently, they are declared before main() is called. Then, paralleling the need to give a variable some meaningful variable before trying to use it, you need to provide the function … | |
Re: Unless you've changed it by now your code has this snippet: [code] int noOfGuesses = 0; int ncount; int sum=0; int noOfguesses; int noofgamesplayed; int avgNoOfGuesses; sum+=noOfGuesses; avgNoOfGuesses=sum/noofgamesplayed; [/code] This: int noOfguesses; is a duplicate of this: int noOfGuesses = 0; and needs to go if you haven't already gotten … | |
I'm frustrated at the moment and thought I'd vent a bit before asking for help. I've finally decided to download MS Visual C++ Express 2005 and migrate from VC++ 6.0. I know, it's about time! What can I say, except that I hardly ever download stuff from the net because … | |
Re: it's at least an off by one error in divisionChange. When y goes from 1 to 3 then y + 1 goes from 2 to 4 but 4 as an index for quarters isn't legal. The legal indexes for quarters are 0 to 3. | |
Re: To look it up it's frequently called a nested loop since one loop sits inside another. Any type loop can be used in either position. Can have more than one nested loop, more than one layer of nested loops, etc. [code] outer loop //control whether to guess a number generate … | |
Re: the simplest place to start is just get the base program running. #include <iostream> int main() {} compile and run that. Then add no more than one function, loop, or control statement at a time and compile, run, test after each addition. Since your file input is standardized you could … | |
Re: I don't see where you initialize standardExemption before you try to use it in calculation of taxableIncome. Once you have taxableIncome you need to subject it to the pertinent tax rate given in the instructions before returning the tax as taxableIncome isn't taxed at 100% (yet, anyway). You can use … | |
Re: At the end of the second for loop count equals NUM_ARRAY. count isn't changed between then and it's use in the terminating condition in the third for loop. This means that in the third for loop numHolder[count] is the same as numHolder[NUM_ARRAY] which is out of bounds. The same argument … | |
Re: In a test program write this: cout << argv[2] << endl; and see what happens. argv[2] IS the equation in the form a C style null terminated string. You can copy this to another C style string using strcpy() or you could initialize another C style string with argv[2] if … | |
Re: Doesn't Ancient Dragon's answer in post #2 of this thread do the trick? | |
Re: void initialize(char letter[26], string food[26], double cost[26]); Just like your answer said in #4: >>so if i din't want to use a struct, each time in my functions where I have fastfood...i'd have to replace it with: char letter[]; string food[]; double cost[]; | |
Re: frame[1].dist[0] This syntax implies that frame is a object for which the [] operator is overloaded-----for example and array, a vector or maybe a map. Assuming it's an array based on your post then frame could be declared one of two ways: Frame frame[MAXSIZE]; Frame * frame = new Frame[MAXSIZE]; … | |
Re: Each line in the file could be read in as a string. The first string would be stored as the correct answer string. The remaining lines alternate between student ID strings and the student answer strings. Once you have a student answer string you compare each element of that string … | |
Re: OK, now use a nested loop to enter data into array. Here's a very basic outline of a nested loop using for loops. You have to fill in the necessary details as per your project instructions. [code] for() //this loop will control which row you're using { for() //this loop … | |
Re: The program is reading the file line by line as written. What it looks like you need to do is figure out a way to parse (break it up into definable chunks) each line. I think you can do it with the getline() version for C strings if you want. … | |
Re: My crystal ball is pretty cloudy right now. If you want more help please be more specific, like post your code (using code tags) and information about what it is exactly that you are trying to do. | |
Re: Will the file be one word per line or do you have to parse the line into individual words. Once you have a single word I'd send it to vowel(). I don't know why you would want to send three strings to vowel(). You don't really need the string word … | |
Re: Data validation isn't an easy process, but it isn't rocket science either. There are two common approaches. The first is to never accept input as any type other than as a string because strings are always valid. Doing this you would then validate that all the characters in the string … | |
Re: Unexpected error of what type? Of hand I'd be concerned that when name == "stop" there is no corresponding score so trying to display one may cause a problem. Alternatively, using ATIME as an index as in below: DisplayArrays(studentNames[ATIME], scores[ATIME]); is an error since the last valid index is ATIME … | |
Re: Declare an array of type student in main() just like you'd declare an array of type int or an array of type double. Also change this: void sets ([]); to something like this: void sets(student studentArray[], int size); and make the appropriate changes in the definition as well. In the … | |
Re: EIther test the name before you enter it into the name array and break out of the loop if it equals "stop" without entering "stop" into the array (which is what I think twomers is suggesting) or, alternatively, leave "stop" as a name in the array, but when you display … | |
Re: Building your first hand rolled linked list is hard enough, let alone trying to do it with templates. As to your post #6 in this thread, there is nothing there that needs something out of namespace std. If you have a statement such as: using namespace std; after you list … | |
Re: Overload the << operator for the struct/class to output all the information you want in one operation using whatever format you want. //declare the struct struct mine {//whatever}; //declare an array of 10 structs of type mine mine myStructArray[10]; If you don't know the number of items to go into … |
The End.