1,426 Posted Topics

Member Avatar for ben1996123
Member Avatar for ben1996123
0
560
Member Avatar for Tom_Weston

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()); …

Member Avatar for Tom_Weston
0
107
Member Avatar for sgiusti88
Member Avatar for NathanOliver
0
309
Member Avatar for sandman64

Look at this [code=c++] // defenition int getNumAccidents(string) // decleration int getNumAccident(string name) [/code] (hint) See how the ( don't line up.

Member Avatar for sandman64
0
154
Member Avatar for Xide

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.

Member Avatar for mrnutty
0
167
Member Avatar for TSaunders84

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]

Member Avatar for Fbody
0
139
Member Avatar for meli123

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.

Member Avatar for mrnutty
0
96
Member Avatar for crownedzero

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 …

Member Avatar for mrnutty
0
111
Member Avatar for monkeybut

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]

Member Avatar for NathanOliver
0
161
Member Avatar for Labdabeta

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.

Member Avatar for BCBTP
0
127
Member Avatar for mimah1
Member Avatar for thenewbiecoder

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.

Member Avatar for WaltP
0
258
Member Avatar for s.tay

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; …

Member Avatar for NathanOliver
0
452
Member Avatar for meli123

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 …

Member Avatar for NathanOliver
0
92
Member Avatar for meli123

Use a char array and a for loop. Store the input into the array and loop through it to find the largest number.

Member Avatar for TrustyTony
0
297
Member Avatar for ThuggyWuggy

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.

Member Avatar for ThuggyWuggy
0
1K
Member Avatar for cent91
Member Avatar for coolbeanbob

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.

Member Avatar for NathanOliver
0
188
Member Avatar for fsefsef23
Member Avatar for iamthesgt

In between lines 5 and 6 try adding [code=c++] timestamp.erase(timestamp.end() - 1); [/code]

Member Avatar for NathanOliver
0
808
Member Avatar for guccimane

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

Member Avatar for WaltP
0
103
Member Avatar for jper

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. …

Member Avatar for jper
0
500
Member Avatar for mullerfourie
Member Avatar for NathanOliver

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 …

Member Avatar for mike_2000_17
0
162
Member Avatar for Vusumuzi

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 …

Member Avatar for Vusumuzi
0
321
Member Avatar for oscargrower11

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]

Member Avatar for oscargrower11
0
210
Member Avatar for NetJunkie

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]

Member Avatar for mrnutty
0
200
Member Avatar for HelpStudents
Member Avatar for rjcenteno

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 …

Member Avatar for rjcenteno
0
182
Member Avatar for hacknayan

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 …

Member Avatar for NathanOliver
0
108
Member Avatar for imraan1992

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 …

Member Avatar for gusano79
1
101
Member Avatar for coolbeanbob
Member Avatar for coolbeanbob

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 …

Member Avatar for raptr_dflo
0
182
Member Avatar for Grovega

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 …

Member Avatar for Grovega
0
181
Member Avatar for webjam

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 …

Member Avatar for NathanOliver
0
126
Member Avatar for RideFire

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() …

Member Avatar for RideFire
0
2K
Member Avatar for coolbeanbob

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 …

Member Avatar for NathanOliver
0
162
Member Avatar for Coffee_Table
Member Avatar for DeftArcher

you need to change your function decleration on line 8 to [code=c++] void Read_Data(ifstream &, string[], double[], double[], double[], double[], double[]); [/code]

Member Avatar for raptr_dflo
0
395
Member Avatar for Clexify

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?

Member Avatar for raptr_dflo
0
333
Member Avatar for ellisrn

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.

Member Avatar for Fbody
0
1K
Member Avatar for kartikkp

since a and b are pointers you need to use the -> operator not the . operator

Member Avatar for NathanOliver
0
159
Member Avatar for miyumi
Member Avatar for Marvin Danni

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]

Member Avatar for Narue
0
124
Member Avatar for SCass2010

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 …

Member Avatar for NathanOliver
0
139
Member Avatar for 4everct01

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.

Member Avatar for 4everct01
0
1K
Member Avatar for YungSoprano

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 …

Member Avatar for YungSoprano
0
609
Member Avatar for xenhancd

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 …

Member Avatar for mike_2000_17
0
235
Member Avatar for mridontknow
Member Avatar for Peter4n31

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]

Member Avatar for Narue
1
158

The End.