1,426 Posted Topics
Re: to sort the list using sort you would have to do [code=c++] sort(theList.first(), theList.end(), compareFunction); [/code] the compareFunction is one that you would have to write to compare the avg of one object to the avg of another object. [URL="http://www.cplusplus.com/reference/algorithm/sort/"]this[/URL] should help you out. | |
Re: The modulo operator simple finds what the remainder is after dividing by a number. So with integer division 20 / 3 = 6 but 6 * 3 = 18 so there has to be a remainder of 2. you get the remainder by subtracting the divisor times the answer from … | |
Re: you should have the input be read in as a sting and test if it is empty. if it is then quit and if it is not then continue. | |
Re: what is the & for in [icode]DLSortedList * newList = new DLSortedList(dlSL&)[/icode]? i think you might want to be doing [icode]DLSortedList * newList = new DLSortedList(&dlSL)[/icode] | |
Re: Could you post your code if you haven't figured it out? | |
Hey All, I just finished my code and it seams to work fine. I'm looking for advice on improving it or making it easier to understand. Its not Fully complete because I only have to set up to take in a number less than 2147483648 because i am using an … | |
Re: [URL="http://www.functionx.com/cpp/articles/filestreaming.htm"]here[/URL] you go. | |
Re: the first is a class inside a class and the second is two separate classes | |
Re: well if you have the read the data in from the file. store the names into an array of a string and the gpa into an array of doubles. I'm not exactly how you are supposed to be sorting the information. the trick is that when you are sorting one … | |
Re: You are right to assume that there will be some code to write but its not that much. If you are going from a five hundred and fifty to 550 needs 3 tables. If you can use the STL than using a map you would be a great way to … | |
Re: Why don't you think your first piece of c++ code wont work? | |
Re: I would have to say that using global variables should not be used. IMHO all variables should either be in a function like main or in a class. It looks cleaner and is better understood if you pass a variable to a function instead of making it global and just … | |
Re: if you are trying to be really efficient with the amount of ram you are using and you need a variable that would hold anything from -10 to 10 then a singed char would work and you are only using 1 byte of memory. | |
Re: Setting you variables to zero on lines 85 and 103 isn't what you should do. You should initialize them to the first value in the array and then check from there. On line 89 you are checking if the lowest temp is less than the array value and if it … | |
Re: What do you mean saying its no longer random? Are you getting the same results each time? | |
Re: if you are asking how to ask for a password then just ask for it inside the while loop. Replace [icode]password = "abc123";[/icode] with code to ask the user for there password and then retrieve the password. | |
![]() | Re: why are you putting a conditional inside the array index? [code=c++] if (paths[sROW][sCOL]==' ' && paths[sROW+1<=19 /*this doesn't make sense*/][sCOL] [/code] |
Re: I know this isn't a solution but it should help. If you know that when using your function trying to calculate a factorial higher than 31 will be incorrect, then you can use an if statement to check the number supplied to the function to see if it is higher … | |
Re: Line 7 should be [code=c++] void Initialize(Book[], int); [/code] And line 26 should be [code=c++] void Initialize(Book arrbook[],int size) [/code] | |
Re: @ Nathaniel using a switch statement would be less than ideal in this case because you have a large range of numbers to work with. Even with fall through you would still need to have 60 cases. | |
Re: have you tried uninstalling and reinstalling the video driver? | |
Re: did you try pulling the cmos battery for a few minutes and then put it back in then give it a boot? | |
Re: To expand on what Gerard pointed out is when you pass an array to a function it actually only passes a pointer to the first element. Since you are working with pointers any change to a value in the array in a function is reflected in main. [code=c++] void foo(int[]); … | |
Re: are you using a loop to read the file and check it against your permuted word? | |
Re: you need to include is_prime.h in your is_prime.cpp file. | |
Re: You should be putting your if statement inside the while loop. The way the program should work is you should read in a city name and then check to see if that city matches or partially matches the city the user entered. If it does output the city name that … | |
Re: A1 in your f2 function is actually using A and not A1. | |
Re: Part of your problem is that your coding style is making it difficult to line parts of the code. The brackets don't always line up and that makes it difficult to find the mismatch. I would suggest you separate each function into its own header file so that you don't … | |
Re: first you need to have a return statement at the end of your mean function to return avg. Also your function prototype and your function definition don't match. Your prototype has a array and a int but you definition has no variables. [code=c++] float mean() { //... return avg; } … | |
Re: i would say your best bet is to walk through your code with the debugger and see what is happening. | |
Re: use the pow function. [code=c++] foo = pow(bar, 3); [/code] | |
Re: you cant because you are reading the file into an int. you will need to read it into a string and then test to see if has a decimal or not. | |
Re: on lines 15 and 17 you are setting your counter variable to -1. when it tries to access element -1 it throws an error. try setting the variables to 0 and see what happens. | |
Re: This is a nice conversion function at will convert any type that has an << operator. [code=c++] #include <string> #include <sstream> template<typename T> string ConvertToString(T & value) { std::stringstream ss; ss << value; return ss.str(); } [/code] | |
Re: So whats wrong with it? Does it not work or are you getting a compiler error? | |
Re: since you dont know what the size of the file will be i would suggest using a container from the STL. that said i will use a vector for my example. [code=c++] vector<string> words; string word; ifstream fin("text.txt") // use ifstream object to get info from file while (fin >> … | |
Re: on line 19 it should be [icode]if (found)[/icode]. the same applies to line 22. also why is found a bool? [EDIT] what are you trying to do with this [icode] found = 2 * a > b;[/icode]? | |
Re: lines 19 through 22 are not actually doing anything. you need to get the words from the file in order to push them into the stack. To get the word from the file into your stack you will need to do something like this. [code=c++] stack<string> Stack; string word; ifstream … | |
Re: I would like to add that you should not be using void main. per the c++ standard main should always return a int. | |
Re: all of your function definitions do not name the variables that you are passing to them. You are also declaring the variables that you are passing to your functions globally. You don't need to have any function parameters if you are only using global variables but I suspect that your … | |
Re: what happens if you change line 32 to [code=c++] double root = sqrt(double(number)) + 1; [/code] [EDIT] I think you might also want to recheck the way you are incrementing your test variable. | |
Re: if you want to store the address of that element in you vector than you can do [code=c++] vector<int*> stack stack.push_back(&(array[1][1])) [/code] if you are trying to store the value of x and y values you can use a 2d vector like [code=c++] vector< vector<int> > stack vector<int> temp; if … | |
Re: if you want to take data in as a string and convert it you can do: [code=c++] // you have to have these #include <strstream> #include <string> int number; std::string input; std::stringstream ss; cout << "enter number: "; getline(cin, input); ss << input; ss >> number; // now number is … | |
Re: What are the errors you are getting? Also your addDay function is not right. it should accept an integer parameter and add that to the current day to get the new day. | |
Re: Are you sure that ContactPtr is holding a BCorp and that it is getting cast right? Also why are you casting objects to a double * in you contact object. | |
Re: i would use a char array for your input but rather a string [code=c++] string input; set<string> dictionary; // open file while(getline(nameFile, input)) // read untill there is nothing left to read { set.insert(input); // insert into set } // print contents [/code] | |
Re: Why are you defining your functions inside main? | |
The End.