1,426 Posted Topics

Member Avatar for Raisefamous

If I was writing a code to compute the factorial of a number I would do this. [code=c++] #include <iostream> using std::cout; using std::cin; int main() { int factorial = 1, number; cout << "Please enter a number to find its factorial: "; cin >> number; for (int i = …

Member Avatar for WaltP
0
259
Member Avatar for emitremmit

On line 50 you are using [icode]j[/icode] without initializing it. Same thing goes for every other time.

Member Avatar for emitremmit
0
277
Member Avatar for Thermalnuke

I'm not sure what you are trying to do between lines 70-81. if you want to find the difference between the 2 times you do[icode]return total_min1 - total_min2;[/icode]. If you want to get to the absolute difference between the two times than you can use the abs function provided in …

Member Avatar for Thermalnuke
0
2K
Member Avatar for PrimePackster
Member Avatar for Semeno

well if you want to search for movies with a particular genre you could use a for loop. Assuming myData is a vector and genre is a string you could use this. [code=c++] string searchGenre; cout << "Please enter the genre to search: "; cin >> searchGenre vector<t_film> matches; // …

Member Avatar for NathanOliver
0
265
Member Avatar for rjstamey

if you want to only get an integer then you could use something like this [code=c++] cout << "Enter menu number: " cin >> number; while (cin.fail()) { cin.clear(); cin.ignore(numeric_limits<streamsize>::max(), '\n') // need to #include<limits> for this cout << "Please enter a valid number: " cin >> number; } [/code] …

Member Avatar for WaltP
0
107
Member Avatar for fmasroor

First [icode]void main()[/icode] is not standard. Main should always return an int. Secondly if you want to use things from the standard library then you will either need to use a using directive or fully qualify the names. [code=c++] #include <string> int main() { string word; // error compiler does …

Member Avatar for Schol-R-LEA
0
334
Member Avatar for fsefsef23
Member Avatar for Moschops
0
167
Member Avatar for sita12345

The problem is that after you get the correct input from the user you are not setting the found flag to true. Add a line to set found to true in your else statement. As a side note the best way to get input from the user that could be …

Member Avatar for sita12345
0
117
Member Avatar for phorce

What tools do you have at your disposal? If you can not use the STL then you will probably want to use a 2d char array. If you can use the STL then a multimap might do what you need.

Member Avatar for NathanOliver
0
92
Member Avatar for james6754

Im pretty sure the reason that you are not getting an exception is because even though you have called delete the pointer still points to the same address. This definitely is dangerous because you have freed the memory so you cant be sure you are not overwriting something else that …

Member Avatar for Moschops
0
124
Member Avatar for tvm78

By default members of a class are private not public. If you want to make them public you need to use the public keyword. [code=c++] class foo { int bar; public: foo() : bar(10) {} int getBar() const {return bar; } } int main { foo temp; int testBar; testBar …

Member Avatar for NathanOliver
0
276
Member Avatar for rjstamey
Member Avatar for Idestruction

The stream class is made for built-in types like int and double it has no idea what a student is. If you want to output it to the stream using cout you will need to write a function that does so. To do that you need to overload the operator …

Member Avatar for Idestruction
0
351
Member Avatar for dakerao

If you just want to keep outputting a+b you could use an infinite loop. something along the lines of [code=c++] while(true) { // code here } [/code] I have to ask why you want to do this?

Member Avatar for Chilton
0
213
Member Avatar for jmaass20
Member Avatar for slygoth

I belive the flags you are using should be [icode]ios::in | ios::out | ios::app[/icode]

Member Avatar for slygoth
0
101
Member Avatar for Nasas

What happenes if you do [code=c++] return to_bin(static_cast<unsigned int>(dec), size); [/code] on line 36?

Member Avatar for Nasas
0
117
Member Avatar for crownedzero

If you want to find the size of a char array and you dont want to use the strlen() function in the cstring header then you can use this. [code=c++] //... char sentence[80]; cout << "Enter a sentence to find the length: "; cin.getline(sentence, 80); int stringSize = 0; while(sentence[stringSize] …

Member Avatar for vidit_X
0
8K
Member Avatar for pendo826

I think you need to describe more exactly what you want to do. Do you want to run through an array of items and display the stats of the items in the array?

Member Avatar for raptr_dflo
0
234
Member Avatar for thecoolman5

Run the following code to see how many digits your double is actually holding. [code=c++] #include <iostream> #include <ostream> #include <limits> int main() { typedef std::numeric_limits< double > dl; using namespace std; cout << "double:\n"; cout << "\tdigits (bits):\t\t" << dl::digits << endl; cout << "\tdigits (decimal):\t" << dl::digits10 << …

Member Avatar for raptr_dflo
0
3K
Member Avatar for pendo826

Is the error from line 111 of you code? You are trying to write to inventory[10] which is illegal because you declared inventory as [icode]inventory[10][/icode]. This means that the valid range for the subscript is 0-9.

Member Avatar for mazzica1
0
257
Member Avatar for skylinedrifter
Member Avatar for jvicta

you need to use the == operator in your if statements not the = operator. == checks if two things are equal and = is assignment.

Member Avatar for NathanOliver
0
314
Member Avatar for TheNNS

Well first off you never reset you loop variable to true after you exit your while loop. Secondly I would change line 18 to [icode]while(getline (myFile,line))[/icode] and then you can delete line 20. As a side note how are you going to handle punctuation marks?

Member Avatar for TheNNS
0
3K
Member Avatar for mcclainra
Member Avatar for gotnos

How are the numbers stored in the file? One per line? If that is the case you might want to use the getline function for your while loop control [code=c++] string number; // open file while(getline(inFile, number)) { nuber.resize(14); // gets rid of any extra letters for (size_t i = …

Member Avatar for WaltP
0
151
Member Avatar for Tom_Weston

Well you could do this [code=c++] size_t pos = 0; string sample = "The man went to the store."; while ((pos = sample.find_first_of("o", pos)) != string::npos) { if (sample.find_first_of("r", pos) == pos + 1) cout << "good"; } [/code]

Member Avatar for WaltP
0
158
Member Avatar for Labdabeta

An array's size is only limited to the memory of the machine running the code. If you want to make an array larger you will need to read up on dynamic arrays. If you need storage that can get very large or you need it to grow I would suggest …

Member Avatar for rubberman
0
142
Member Avatar for toneranger

Well you could store the data in a set and define a comparison function that sorts the data by the lowest price. After reading the contents into the set and the first element of the set should be the one with the lowest price. [code=c++] class comparePrice { bool operator()(const …

Member Avatar for toneranger
0
855
Member Avatar for Tom_Weston

To find if a letter is in the string then you can do [code=c++] string sample = "have a good day."; if (sample.find_firt_of("ha", 0) != string::npos) [/code] The above example will only check to see if there is an 'h' or an 'a' in the string. It does not check …

Member Avatar for MonsieurPointer
0
113
Member Avatar for Zssffssz
Member Avatar for Tom_Weston

Well you can use a counter variable and increment it until you find the word. [code=c++] //... int lineCount = 1; while ( myfile.good() ) { getline (myfile,line); if(line == word) { cout << "Walked was found on line " << lineCount; } else { lineCount++; cout << line << …

Member Avatar for Tom_Weston
0
88
Member Avatar for trantran

Well you can do like the standard library does and say that a iterator a pointer to the data of a class is only good until the next time you use the object.

Member Avatar for mike_2000_17
0
101
Member Avatar for infoJUNKIE121
Member Avatar for NathanOliver

Hey all, Three times today on three different computers when I went on to this site, specifically the c++ forum, I have received a anti-virus report warning me about an attack site. Has anyone else had this problem? I am attaching a screen shot of what Norton reported. Nathan Oliver

Member Avatar for NathanOliver
0
92
Member Avatar for doomsday1216

one way to convert an int is to use the a string streams. Another way is to use the function atoi(). [code=c++] #include <sstream> // for stringstream #include <iostream> #include <string> #include <cstdlib> // for atoi() using namespace std; int main() { int a, b; string number = "12345"; stringstream …

Member Avatar for mike_2000_17
0
284
Member Avatar for Tom_Weston

The first parameter of substr() is where you want to start so you don't want to start at the comma. you want to start at zero and go untill there is a comma. To do that you can do this. [code=c++] string str1 = "hello,friend"; string str2 = str1.substr(0, str1.find(",")); …

Member Avatar for gerard4143
0
137
Member Avatar for James19142

line 2 in your in the cpp file should be [code=c++] fraction fraction::addFractions(fraction two) [/code] The reason it was not working they way you had it was because you did not have the return type in the deceleration.

Member Avatar for James19142
0
879
Member Avatar for twicepipes

Now when you say any sequence of A-F do you mean you are only checking 6 characters sized strings like ABCDEF, ACBdEF, ACDBEF, .... If that is the case then something like this should do the trick. [code=c++] string sequence = "ABCDEF" string random; // has a random mix of …

Member Avatar for vijayan121
0
265
Member Avatar for myrongainz

if you want to get a positive number from the user try this out. [code=c++] int number = -1; while(number < 0) { cout << "please enter a positive integer: "; cin >> number; } [/code]

Member Avatar for sundip
0
419
Member Avatar for Tom_Weston

More than likely ShellExecute take a const char array. If that is the case try [code=c++] ShellExecute(NULL, NULL, run.c_str(), NULL, NULL, SW_SHOWNORMAL); [/code]

Member Avatar for Tom_Weston
0
176
Member Avatar for Sunshine2011

To pass a vector by reference to a function like your add function you can do this. [code=c++] //prototype vector<int> & AddElement(vector<int> & container, int foo); // definition vector<int> & AddElement(vector<int> & container, int foo) { container.push_back(foo); return container; } [/code]

Member Avatar for vijayan121
0
159
Member Avatar for Kron
Member Avatar for Narue
0
239
Member Avatar for Kron
Member Avatar for temmyb

what is the value of num1 before you try the division? Use a cout statement to see what it is.

Member Avatar for temmyb
0
211
Member Avatar for cossay

The problem is you defined you function as using ofstream and ifstream. These are the objects used for handling files. If you want to use you class with cin and cout you need to use istream and ostream.

Member Avatar for cossay
0
118
Member Avatar for D.M.

I have to go with MSVC++ 2010. I really love the debugger and if you mistype a variable name it will get a red underline letting you know it doesn't know what it is.

Member Avatar for pseudorandom21
0
327
Member Avatar for caut_baia

You don't need to install Linux. You can install code::blocks and then link it to a gcc compiler. Check [URL="http://www.daniweb.com/software-development/cpp/threads/370828"]this[/URL] out.

Member Avatar for caut_baia
0
443
Member Avatar for Wootens

If you don't have to reinvent the wheel I would suggest using the std::list. For your code that you provided though line 37 looks wrong. what happens if you change it to [code=c++] current->next = new teachersList(inTeacherName, inTeacherID); [/code]

Member Avatar for doug65536
0
115

The End.