565 Posted Topics

Member Avatar for mrnutty

First off, if you want some constructive feedback my immediate question is why, (a) you are learning C++/programming for fun and decided to write some code and want to have some feed back. (b) you are taking a class and this is to be marked, and you are hoping to …

Member Avatar for mrnutty
0
487
Member Avatar for mibit

Mynameisor is incorrect about point 1. But this is clean code that you have copied from the answer book. With your current pathetic knowledge HOW do you think you are going to get away with submitting it?? Where is you [B]EFFORT[/B]? Not immediately obvious, so my effort is suddenly lacking.

Member Avatar for brechtjah
0
576
Member Avatar for rottmanj

First, please please look at boost::multi_array or similar structures. This is were the vector formalism really doesn't do anyone any favors. [URL="http://www.boost.org/doc/libs/1_37_0/libs/multi_array/doc/index.html"]http://www.boost.org/doc/libs/1_37_0/libs/multi_array/doc/index.html[/URL] Next row can only have a [icode]vector<vector<string> >[/icode] pushed back to it. col is a vector<std::string>. So that doesnt work. You seem to be using it as a …

Member Avatar for rottmanj
0
2K
Member Avatar for Foe89

Sorry but your errors include : [icode]else {player = 'O' && num++;}[/icode] And that is equivilent to [code=c++] player = ('O' && num); num++; [/code] That means that player == 1 or 0, and both of those are [I]interesting[/I] ascii characters to print :) hope that helps. Overall, laying out …

Member Avatar for StuXYZ
0
168
Member Avatar for StainlessSteelR

All the above posters are completely correct. You really can't size arrays like that. BUT -- Please before you go any further, write down on paper your algorithm. i.e. what is going to happen. The work it through on paper. You then play the routine on paper with the short …

Member Avatar for VernonDozier
0
733
Member Avatar for robgeek

Just in case you forgot. You can easily append to the end of the file. Use [code=c++] std::string input="Hello at the end"; std::ofstream File("file1.txt",std::ios::app); File<<input<<<std::endl; // This is written at the end of the file. [/code] Obviously, if you don't want to change the original, you need to make a …

Member Avatar for StuXYZ
0
168
Member Avatar for fatsbear

First off: [B]and most important[/B] Fatsbear please read the first announcement in this forum about code tags. Then use them. Second: The problem is the association between calories and the food name. You will find other posts, by your classmates I suspect, who have solved the problem by sorting on …

Member Avatar for StuXYZ
0
116
Member Avatar for brixton

Sorry but I am going to disagree with Freaky_Chris for the second time in two days! I hope he realizes the I agree with him most of the time :) Anyway, you MAJOR sin is to think that reading into a class which may or may-not allocate memory will work. …

Member Avatar for Lerner
0
176
Member Avatar for FTProtocol

Can I just suggest the boost filesystem code. If you follow the link, you will see that the first thing in the tutorial is how to find a file. The big advantage is it is operating system independent. [URL="http://www.boost.org/doc/libs/1_31_0/libs/filesystem/doc/index.htm#tutorial"]http://www.boost.org/doc/libs/1_31_0/libs/filesystem/doc/index.htm#tutorial[/URL]

Member Avatar for StuXYZ
0
396
Member Avatar for SoulMazer

I guess you want to write this [code] def vocabtest(): for value in testwords: print "What word does the following definition correspond with?" print value answer = raw_input("> ") if (answer == testwords[value]): print "Correct!" else: print "No the answer is ",testwords[value] [/code]

Member Avatar for SoulMazer
0
311
Member Avatar for vikashkumar051

The lack of initialization is a problem I fully concur with. But your maths is junk. You are multiplying a side length an angle in degrees!!! Try some trig. You want to do it is set [code=c++] x_coord[i]=x_coord[i-1]+side_length*sin(angle); y_coord[i]=y_coord[i-1]+side_length*cos(angle); [/code] Note that you are setting the next point based on …

Member Avatar for StuXYZ
0
144
Member Avatar for minas1

Well first off you are trying to get a protected object. Second even if the object was public you are trying to get it as a static object. So you need to (A) make the object static and then it there is only one version in all instances of the …

Member Avatar for minas1
0
87
Member Avatar for ohlaph

C++ streams have to be treated with a little respect. You have assumed that the only error condition is eof. That might be true if you were reading into values BUT you decided to use peek. Peek CAN set fail(). You do not check eof BEFORE the peek so when …

Member Avatar for StuXYZ
0
128
Member Avatar for SobigR

First off -- You know about loops, so what is that monstrosity of a list of stuff deciding who has won. Why not use a loop. The problem is actually in the last two else if statements. board1[5][5] which does two things. (A) there is no board[5][5] the array is …

Member Avatar for cikara21
0
182
Member Avatar for kyosuke0

This is easy.... Count If you get below zero then you have failed, and if you get not-zero at the end you have failed. You might want to check scope bridges. I.e. [icode](a{b+c)}[/icode] which I would pass as fail. but that is easy to modify the code below to include. …

Member Avatar for kyosuke0
0
202
Member Avatar for sleepytoast

First off you need to read the srand information on the web try [URL="http://www.cplusplus.com/reference/clibrary/cstdlib/srand.html"]http://www.cplusplus.com/reference/clibrary/cstdlib/srand.html[/URL] and understand that you are setting a seed. That means do it once and unless you want the same numbers again do not do it twice. Since you are setting it with [ICODE]time(0) [/ICODE]and most short …

Member Avatar for VernonDozier
0
126
Member Avatar for jbody

sorry but the book is correct. It is a double pointer because it represents a set of strings. For example it might be [code] /* Effective what it is. Not real code */ argv[0]="this program"; argv[1]="option"; argv[2]="another option"; [/code] It is perfectly correct to ask stuff like what is the …

Member Avatar for ArkM
0
119
Member Avatar for azagorath

Assuming that you have a source array that isn't abc... then you want to do it with one + one loop. I don't know why you read only 26 characters from the keyboard line. What if I have a long sentence ... If you have a loop in a loop …

Member Avatar for azagorath
0
279
Member Avatar for teddybouch

You haven't posted enough to figure thst out certainly. My guess is that x and/or bestP are double/float etc and you are committing the cardinal sin of using == with floating point numbers. I am guessing that x is very very close to bestP but that one is held in …

Member Avatar for teddybouch
0
122
Member Avatar for geekru2

The obvious (to me anyway) way round this is to create a base class to either message or to dataPacket. e.g. [code=c++] struct baseMessage { int messageId; int senderId; int recvId; }; template<typename TX> struct message : public baseMessage { dataPacket<TX> data; }; [/code] Then store a pointer to the …

Member Avatar for StuXYZ
0
176
Member Avatar for Freaky_Chris

[B]Floating Point Result[/B] I would like to comment that the issue of getting 0 or getting 5.77e-17 is mainly a CPU issue. Intel and AMD use 80bit registers. This hides and creates a lot of numerical rounding error. This is a nightmare in numerical code since as the code gets …

Member Avatar for StuXYZ
0
263
Member Avatar for benji_k

I am going to comment on the maths/computing interface. You have two problems here, first is that although mathematically correct, the formula [tex]\frac{-b\pm\sqrt{b^2 - 4ac}}{ 2a}[/tex] is is awful as a computational base, since, as you partially discovered, if a or c are very small you get junk. So you …

Member Avatar for benji_k
0
145
Member Avatar for serkan sendur

Actually, it is simply to use [code] gcc -shared -o libmyshared.so file1.o file2.o [/code] Have a look at the gcc manual. [URL="http://gcc.gnu.org/onlinedocs/"]http://gcc.gnu.org/onlinedocs/[/URL]. The only thing that you will need to be a little careful of is were to put it so that it is system wide. That is normally defined …

Member Avatar for serkan sendur
0
131
Member Avatar for csaund1

Think about how you add up. Suppose I ask you to add the number in the series 2,6,9. you don't go let me put the numbers into an array. you simply keep a running total, So in your case start a total total=0 then IF the number is >0 add …

Member Avatar for chococrack
0
178
Member Avatar for thinfineline

[QUOTE=thinfineline;748967]I'm trying to get the game below to work with 2 players. It's setup the way I need it (even the entering the numbers for the die instead of using a rand function and not allowing the bet amount to change(crazy teacher)) [/QUOTE] First off you teacher is trying to …

Member Avatar for StuXYZ
0
415
Member Avatar for DemonGal711

First off. What do you want to do about multiple edges? The problem you have is that link-lists are very specialized graphs, in which they connected linearly as A-B-C-D. So do define topographic graph in the sense of your diagram, you are going to have to add some additional linkage …

Member Avatar for DemonGal711
0
182
Member Avatar for namehere05

[QUOTE=ArkM;748739]Remember the K&R masterpiece: [code=c] while (*dest++ = *src++); [/code] Unforgettable Algol 68's genes are still alive in C and C++ ;)...[/QUOTE] can I just add, you need to remember to add a [icode]*dest=0;[/icode] line after the while. You will need something similar in any of the other posts.

Member Avatar for namehere05
0
614
Member Avatar for Prashant45

Please read the posting FAQ. Then try again AFTER cutting down this junk to a small testable sub-program that shows the same errors. Also I am not answering post that put "Please help as soon as possible , as i have to complete the project". It is your assignment and …

Member Avatar for ArkM
0
2K
Member Avatar for Proseidon

A few points: Sorry to preach... You allocate 33971 lists!! Much better is to use a map. std::map<int,std::string> If you want to record clashes then us a multimap. Next: Why open all the files at once, have one ifstream and open a file, process and open the next file. C: …

Member Avatar for ArkM
0
156
Member Avatar for markd220

I have seen this problem before. I would advise (a) Never round up/down until the end. (b) It is tempting to count the large number significant bits in the input data e.g. if the user enters 3.45 lb + 12.3 oz. And then say round to 3 sig.fig. but you …

Member Avatar for markd220
0
132
Member Avatar for clutchkiller

As has been repeated many times in the last few days. You cannot declare anything in the outside scope of a case statement. you need either to put cList outside of the switch or use something like this [code=c++] case 4: { ofstream cList; // ..... stuff } break; case …

Member Avatar for cikara21
0
217
Member Avatar for Lrddpy

Yes, this case I would post the code. I figure that (a) you have actually googled this. (b) and tried some testing. (c) your using a compiler that give better error messages that VC++. However, this is not a completely uncommon error so I would like to explain what it …

Member Avatar for Lrddpy
0
231
Member Avatar for Shinedevil

I think that it is easier to get the input as a string and then parse it using a stringstream. If that is successful you have a number. If not then you don't. The problem with isdigit etc, is say you want to enter 1.43e-7. Failes on e and -. …

Member Avatar for StuXYZ
0
202
Member Avatar for bradbobak

Yes it did. There were are number of horrible errors associated with gcc-3.4 series on reverse iterators. You have to use == and !( iter == v.rbegin()) or as you say write you own. I am sorry but I pity you having to write for 3.4. (My problem is I …

Member Avatar for bradbobak
0
125
Member Avatar for serleon

First off welcome. I think this looks like particle physics code :-) In particular Cern style code. Looks like you are going to have fun. Swot: I am going to disagree with Swot since it doesn't compile. You can't add a char to a char array. Infarction: Sorry, I think …

Member Avatar for StuXYZ
0
403
Member Avatar for mybluehair

I think that the problem is that section is a char array and you have the problem that you have to convert them to integers first, otherwise they have their ascii value. e.g. 1 is 49 (I think) So isolate the number part of section and convert to an integer/double …

Member Avatar for Freaky_Chris
0
110
Member Avatar for robgeek

You error is the fundamental language mistake. It is not possible to declare any new variable or object in the scope of the switch statement that has outside scope. [icode]ifstream input("help.txt");[/icode] is not allowed. Additionally, you have already declared input at the top [4 lines below main()]. If you want …

Member Avatar for robgeek
0
4K
Member Avatar for Taker

uinput is defined as an integer / and 'N' is not. (actually, N is converted to an integer but as its ascii value) Adding some structure to this would greatly help. Use some functions etc. Separate the question/answer from the actual processing. That also allows you to write tests easily. …

Member Avatar for WaltP
0
208
Member Avatar for g_loughnan

From looking at you code I don't think you are clear on (a) the objective (b) how to use const references. So I am going to re-write a bit to do something (Unlikely to be what you want) but hopefully that will separate between (a) and (b). Let us start …

Member Avatar for StuXYZ
0
620
Member Avatar for Lotus_2011

You have not defined a few components. e.g. you need to add a destructor Stack::~Stack() { // stuff } etc.

Member Avatar for StuXYZ
0
1K
Member Avatar for mridulsouth

Why not use a string Add [icode] #include <string> [/icode] at the top replace char* ... with this [icode] std::string str; [/icode] // and and change your output line to this.... [icode] std::cout<<"Length == "<<str.length()<<std::endl; [/icode] note that since string is a class, and str is an object of type …

Member Avatar for MosaicFuneral
0
118
Member Avatar for MJFiggs

You have missed that you could have 2 aces e.g. AAK45 would be 21 but you will not score it as such. So ADD 10 if you have an ace. Since you can't have two. as AA+ 20 == 22. e.g. lines 42-46 become [code=c++] if ((dHand < 12) && …

Member Avatar for MJFiggs
0
120
Member Avatar for daviddoria

The difference between (int) and static_cast<int> is really the limitation of static_cast<> I think it is easier to see an example and then discuss it. E.g. [code=c++] char A('x'); double X[50]; int i=static_cast<int>(A); // OK int k=(int) A; long int j = (int) X; long int k = static_cast<long int>(X); …

Member Avatar for StuXYZ
0
104
Member Avatar for JackDurden

It depends on what you want to do with the code. If you want a vector of all the words or a particular one Try this [code=c++] std::string Text; // set text equal to something ... std::string searchString="(\\S+)\\s"; boost::regex Re(searchString); std::vector<std::string> Aout; boost::regex_split(std::back_inserter(Aout), Text, Re); // Destroys Text string in …

Member Avatar for StuXYZ
0
107
Member Avatar for anupamsps

You seem to be doing what every condensed matter phys. student does a sometime that is to write an atomic simulation. So I am assuming that is so. What you want is to have a multimap that allows you to quickly obtain those particle of a particular type or you …

Member Avatar for StuXYZ
0
179
Member Avatar for pragtos

Classic error: Line `if (choise = y)` This ASSIGNS choise to be y, and then check to see if it is not zero. Also you don't need the "do" after the if construction. This tell me either (a) you are using a very old compiler or (b) you ignore the …

Member Avatar for pragtos
0
124
Member Avatar for ttano173

Hi Ok in no particular order a few problems with this code + the fix for your compile problem. (I hope) the do { } while loop in main is a double test, try something like [code=c++] int flag; do { singleChar=getChar(); flag=validateChar(singleChar); if (flag) std::cout<<"valid"<<std::endl; else std::cout<<"no valid"<<std::endl; } …

Member Avatar for ttano173
0
372
Member Avatar for XxAaronxX

The mistake is that you are using integers (the set 0,1,2,3 and -1 etc) to represent floating point number. [icode]int a=2*1.2;[/icode] gives sets a to 2. write [code=c++] double Meters; double Yards; [/code] instead of the two int declarations.

Member Avatar for XxAaronxX
0
100
Member Avatar for Jason123

I am assuming that you have googled this and are confused, so I will take a stab at explaining it but feel free to ask questions. Composition is to contain. An example is easiest [code=c++] class Wheelbarrow { private: Cement A; Water B; Sand C; }; [/code] The class contains …

Member Avatar for Alex Edwards
0
795
Member Avatar for minas1

In order: 1) Yep 95% of the time, the thing to do is return a reference. It is not obligatory, for example you could return a flag (for example on a cyclic counter as it loops over) 2) [code=c++] loc& operator++(); // prefix loc& operator++(int); // postfix [/code] Note that …

Member Avatar for minas1
0
164

The End.