1,426 Posted Topics
Re: You haven't set the values for the systems in the second block of code. | |
Re: If you want to get the file name from the user and then open that file do this [code=c++] #include <string> #include <iostream> #include <fstream> using std::string; using std::cout; using std::cin; using std::ofstream; int main() { string filename; cout << "Please enter the filename: "; cin >> filename; ofstream fout(filename.c_str()); … | |
Re: The problem is that when you find a new max or 2nd max you need to reset the counter back to 1. | |
Re: Look at this [code=c++] // defenition int getNumAccidents(string) // decleration int getNumAccident(string name) [/code] (hint) See how the ( don't line up. | |
Re: You cant do that in c++. All variables must be declared before compilation. if you want to get n inputs you will either need an array or some sort of container like a vector. | |
Re: I think what you are looking for is a 2d vector. If that is what you are trying to do than to declare a 2d vector use [code=c++] std::vector<std::vector<string> > rows; [/code] | |
Re: A bool can be thought of as an int with a range 0f 0 to 255. As such a 0 means false and anything else is true. | |
Re: Ell you can only return one variable. If you want to return information from your function to more than 1 variable you will need to pass the variable into the function by reference or a pointer. That said I think a reference will be fine for you. See how this … | |
Re: Lines 27 and 31 are incorrect. You have [code=c++] if(nametag == "lastname" || "surname") // which translates into if(nametag == "lastname" || true) // which translates into if (true) [/code] What you need to do is [code=c++] if(nametag == "lastname" || nametag == "surname") [/code] | |
Re: Tell the person you are programing with that this is c++ not java. Creating a class that is just holding the math functions is unnecessary. You can just call them when you need the without having the overhead of creating a class. | |
Re: What happens if you remove your call to sort? | |
Re: well you need an ofstream object opened to the file that you want. after you do that in for loop output the char array to the file using the >> operator. | |
Re: Do you want to round the number? Like 3.7 becomes 4 but 3.2 becomes 3 or do you just want to drop the decimal part? If you just want to drop the decimal part you could do [code=c++] double doubleArray[60]; int intArray[60]; for (int i = 0; i < 60; … | |
Re: The modulo operator is the remainder operator. it says what is left after I divide x by y. So if you do 10 % 2 you get zero because 10 / 2 = 5 with nothing remaining. If you do 10 % 4 you get 2 because 10 / 4 … | |
Re: Use a char array and a for loop. Store the input into the array and loop through it to find the largest number. | |
Re: line 52 should be [icode]Stack g;[/icode]. The reason for this is the compiler is interpreting line 52 as a function that returns a Stack and takes no arguments. | |
Re: What are you trying to do where you need these functions? | |
Re: Line 9 cant be blank because you have to do something with the parameters you pass it. Lines 23-24 are there to compare a double value against the volume of the box. | |
Re: in main you would do [code=c++] intList.reversePrint(cout); [/code] | |
Re: In between lines 5 and 6 try adding [code=c++] timestamp.erase(timestamp.end() - 1); [/code] | |
Re: To get the last letter from a file you would use [code=c++] //... ifstream fin("input.txt"); fin.seekg(ios::end); char ch; fin >> ch; if (ch == '+' || ch == '*') //... [/code] Also it is bad practice to use the goto command | |
Re: If you can use STL then you could use the random shuffle algo. Since I don't think you can use that algo you would need to use two for loops. One to populate the array with the numbers 1-20 and the other to swap the elements in the array around. … | |
| |
Hey all, I was taking a look at my stringstream conversion function and I couldn't decide how I want to handle a bad conversions. I used an exception and then in main I would a use a try, catch block to get any exception. [code=c++] #include <sstream> #include <exception> class … | |
Re: I believe the reason for this is the or in the while condition. If you change it to and it will work. If I remember correctly this happens because the compiler evaluates the whole statement and causes a false negative. I know there is a post on here about this … | |
Re: the reason he has it returning the an istream reference is to be able to chain it. by that I mean [code=c++] cin >> input >> anotherInput >> read_hw(cin, homework); [/code] | |
Re: To follow WaltP's adive you could simply do [code=c++] srand(unsigned(time(0))); string names[] = {"Jim", "Tom", "Jeff", "Larry"}; cout << "The person that should drive is: " << names[rand % 4] << "."; [/code] | |
Re: Are you supposed to implement your own list class? | |
Re: You might be able to do something like this. [code=c++] //... if((strcmp(token[0], "PRISM") == 0)) { if((prismSide1 = atof(token[1]) = 0.0); run error code if((prismSide2 = atof(token[2]) = 0.0); run error code if((prismSide3 = atof(token[3]) = 0.0); run error code prismCalc(prismSide1, prismSide2, prismSide3); } //if //... [/code] Personally I would … | |
Re: well if that is the only data in the text file and there is a space between the : and the info you want then it is pretty simple. You read in the first part of the line into a dummy variable and then the you read in the second … | |
Re: look at this part of your code [code=c++] for(int n=0;n<11;n--) [/code] What happens to n as the loop goes on? Does n ever become greater than or equal to 11? Your else statement is also wrong. Have you ever seen [icode]else[/icode] followed by a condition? [URL="http://www.intap.net/~drw/cpp/cpp04_02.htm"]here[/URL] is a link for … | |
Re: What are the error that you are getting? | |
Re: If you are checking that data inside the containers against the supplied response then you might want to think about using templates. Here is a simple way to check through containers using iterators. [code=c++] template<typename ForwardIterator> void CheckResponse(int response, ForwardIterator first, ForwardIterator last) // last should be one past the … | |
Re: The problem with your algo is that when you get to numbers like 15 which are divisible by both 3 and 5 you add it in twice. I think a a better way would be to use one for loop from 3 to 1000 and check with an if statement … | |
Re: The second is invalid. Only a pointer to can use the new operator. Here is a little breakdown for you. [code=c++] int foo = 10; // normal assignment; int *fooPointer = new int; *fooPointer = foo; // now fooPointer is a pointer to an int that holds the value of … | |
Re: The way I would go about this is to use a prime number function. Then use a while loop to keep track of how many sets of primes you have found [code=c++] bool isPrime(int number) { // put code here to check if a number is prime; } int main() … | |
Re: When you declare an array or a vector you don't subtract one from the size when you declare it. [code=c++] int foo[30]; // creates a array of size 30 indexed from 0-29 vector<int> bar(30); // creates a vector of size 30 indexed from 0-29 [/code] if you do [code=c++] int … | |
Re: I would have to agree with caut_baia that we need to see find_original and also some more of your code. | |
Re: you need to change your function decleration on line 8 to [code=c++] void Read_Data(ifstream &, string[], double[], double[], double[], double[], double[]); [/code] | |
Re: you need to reset your i variable back to zero after your for loops that start on lines 8 and 34. By the way what exactly are you trying to accomplish here? | |
Re: well to keep kicking the dead dog. Fboady it is true that a 32bit int is aprox -2 bil to 2 bil but 100! is 9.3326215443944152681699238856267e+157 which is way out of range for an int on even a 128 bit system. | |
Re: since a and b are pointers you need to use the -> operator not the . operator | |
Re: Please post an example of what you are trying to do | |
Re: What are you trying to do with it? Also please use code tags when posting code. I would also change your for loop to [code=c++] for (size_t i = 0; i < str.size(); i++) { //... } [/code] | |
Re: on lines 64 through 67 you are passing the drivers address to the functions but you defined the functions as taking a driver by value. Here is the different ways you can pass an argument to a function. [code=c++] #include <iostream> using namespace std; int PassByValue(int value) { return value … | |
Re: What is user input declared as? It looks as if you a re trying to use an initialize list. Make sure your compiler is able to use that feature if that is what you are doing. | |
Re: Why are you including a .cpp file? The general structure of the the files should be like main.cpp: This is the cpp file where main is. You can call it anything. In this file you will include all header files needed className.h: This is where the declaration of the class … | |
Re: line 29 should be [icode]total = total + price[count];[/icode]. What [icode]total = total + price[/icode] does is say add total to the address of the first element in prince and then store it in total. You cant do that because total is a double. What I did say to add … | |
Re: What happens if you try this [code=c++] CDirLoader::GetFileExtHandle(not related params) { std::string prefDir; for(size_t i=0;i<preferredPaths.size();++i) { if (!preferredPaths[i].empty()) prefDir = preferredPaths[i]; //... } } [/code] |
The End.