2,045 Posted Topics
Re: Would it help you to know [code] char a = '1'; a++; [/code] will give you '2'? Now use the array indicies to offset the value by the number of rows (with the appropriate number of columns) and by the leftover columns. Trial and error should get it if nothing … | |
Re: EOF is not a string it's normally a negative integer. Use your getline function to drive a while loop. I would suggest the following though someone probably has a better solution which doesn't require the user to press enter twice (as it's just not clicking with me today). [code] while(getline(cin,str,'\n')) … | |
Re: What is the problem you are experiencing with the code. That's what Zcool is trying to get you to express. "It doesn't work" is not enough for anyone to go on. What do you expect from it and how is it breaking? If you don't know that go back and … | |
Re: (x - checksum) must be less than 100 AND (x - checksum) must be greater than -100 (or you can use absolute value but this is much cheaper) | |
Re: Your code is kind of all over the place. The first thing you should be aware of is the syntax for declaring and defining a function (here is a rough layout): [code] #include<iostream> using std::cout; //can also put "using namespace std;" (no quotes) //but that can clutter up your namespace … | |
Re: I believe if you specify a constructor other than a default one you must define a default one. So just pop it into the header file of your class (as you only need the [icode] MyConstructor {} [/icode] variety). Then you won't even need it in your implementation file. | |
Re: Try it out on paper for something simple like 10/2 (repeat your subtraction of until you get to zero). A pattern will emerge. Determine a "base case" when you should stop subtracting. | |
Re: I'm confused. "tags" is an int (line 16), and you're reading into like it's a string (line 41) and you're trying to compare it to multiple characters (line 56) within a spot for a single character (single quotes). I'd say grab a good book and spend at least a week … | |
Re: What is the message with the error that it is giving you? | |
Re: Is there a reason for returning 0 from your methods regardless of the outcome. Also in your definitions you need to put the return type [COLOR="Red"]int[/COLOR] [icode]Complex::Set_C(double x,double y) [/icode] though I suspect you made them ints to make the compiler happy anyway which isn't the right approach. If you're … | |
Re: Big question what is the access specifier of all of these? [code] bool DieselTypeStatus; //ok Truck(); //ok void Truck(bool); //wrong - no return type ~Truck(); void DieselTypeStatus(bool); //wrong-duplicate name bool getDieselTypeStatus()const; [missing - declaration for setDieselTypeStatus(bool)] [/code] | |
Re: You don't need to pass in another string to your show() method as you already have access to the one within the object. It should just be [icode]cout <<p; [/icode] or you can [icode] #include <cstdio> and use puts() [/icode] P.S. When you are asking for help in the forums … | |
Re: You only did the calculation once: [code] double angle=0; double sinAngle = sin(angle); [/code] This doesn't magically assign that function to sinAngle, it evaluates it at angle 0 and prints it over and over again in your loop. Leave the declaration [icode] double sinAngle; [/icode] outside and move the [icode]sinAngle … | |
Re: im not going to write you the code so you can submit it your teacher Spend about 5 additional minutes on the site and you'll realize this is absolutely absurd. I respect your freedom to express your opinion (whether I agree with it or not is another story), could you … | |
Re: What doesn't work about it? Also please enclose your code in code tags: [noparse] [code] //code goes here [/code] [/noparse] There's still a few minutes left on your editing time for it. | |
Re: Do you actually need the numbers for calculation within your method? If not just take them in as char and check versus '1' (etc.) in lines 10-17. If you really need the numbers themselves, take them in as char and convert to the numerical value by subtracting '0' e.g., [code] … | |
Re: You have a series of if/else if statements where those variables are assigned with no else statement at the end. What happens if the system goes through those choices and your value doesn't fit any of the criteria -- the variable goes unassigned. So either make your last else if … | |
Re: Firstly f_int takes a double for a parameter and x is a character. Beyond that, though, when you read the value into the function f_int doesn't suddenly become that function. Each time you use that function name in I_simpson that method will be called again and you will be reprompted. … | |
Re: So start by asking yourself what would 1 iteration look like, then 2, then 3. Find the commonalities and use your loop to automate the whole thing. In doing these types of computations generally 2 variables are used, one that holds the prior value, one that holds the next value … | |
Re: Change your while loop to a do/while loop with the same loop condition. Move your prompt for the salesperson number into the loop. That way it's called the first time through and any subsequent times. Line 20 has the incorrect format specifier for a double, it should be %lf instead … | |
Re: Anytime you have an if statement without braces following it, only the next line down is included as part of the if statement. [code] if (condition) x = y; //what gets evaluated pending true condition cout <<"whatever "; //new program statement, if statement done else //compiler says where did this … | |
Re: Check out AD's [URL="http://www.daniweb.com/code/snippet249201.html"]code snippet[/URL] it's about file sizes but the code to traverse the directories should be along the lines of what you want. All else fails, google it again. | |
Re: FWIW, nobody's mentioned it yet -- but check out [url]http://gmplib.org/[/url] | |
Re: Use ./ that will go element by element (I'm assuming that's what you are looking for). If you're looking for matrix inversion times another matrix than for inv(A)*B you need A\B. | |
Re: Welcome. What have you written so far? If you haven't started writing what do you have for information on the dates of the divisions? | |
Re: Create your own class with + - * / overloaded. This is an [URL="http://www.c-sharpcorner.com/UploadFile/prasadh/OperatorOverloading11142005003229AM/OperatorOverloading.aspx"]example for matrices[/URL] but it's similar (complex will be less complicated). Give it a go and post back when you get stuck (or if you have code already post it and someone can look it over). | |
Re: It's going to be tricky because we don't have access to your libraries. I'm sure they are wrappers for the standard functions but that's not a given. | |
Re: Welcome. What do you have so far? I'm assuming you've done some work with OOP concepts beforehand so which do you think would be most appropriate? | |
Re: Just start j off at i+1. That way you're comparing 0 with all the rest, 1 with from 2 onwards, etc., etc. If you need to keep track of whether or not you find a birthday more than twice keep the values in an array and check your new entry … | |
Re: [quote]The Soda class should include the pure virtual function while the Juice class should include the other virtual function. [/quote] My stuff is a bit rusty so bear with me if I'm missing something obvious but aside from varying the access specifiers (pub,priv,prot) of the two methods and using a … | |
Re: I didn't compile and run your program yet, but try putting the srand() call out in main() so it's only done once. | |
Re: The problem is that I believe that a majority of folks on this board run the VC# IDE. Without loading it up and running it we can't tell what's the normal setup for Mono. A suggestion I've given to other users with that IDE is to tag your posts with … | |
Re: Everything you always wanted to know but were afraid to ask: [url]http://oreilly.com/catalog/make3/book/index.csp[/url] | |
Re: Are you allowed to pass anything into ReadQuestion? somehow you have to send the streamreader object in so it can maintain the position in the file each time. Also, there's no way to access the private question variable in the TriviaQuestion class. | |
Re: main should always return an int, not be void. You need to make x and y reference variables, otherwise you're passing them in and they are changed but this is not reflected in the original variables. [icode]void A(Complex a,double & x,double & y) [/icode] | |
Re: Wow. I'm speechless and totally honored. I'll have to return the favor: [B]Nick Evan:[/B] Well what can I say a great moderator and a great guy( when he's not [URL="http://www.daniweb.com/forums/thread255764.html"]running over elderly men on their bikes off the road for the sake of a good story[/URL]). When I first got … | |
Re: Place it inside of main() [code] int main() { srand( time(0) ); [/code] A seed is a starting point in the internal sequence for a pseudo-random number generator. Giving the same seed twice would result in the same sequence of numbers. For more info, check out the tutorial on [URL="http://www.eternallyconfuzzled.com/tuts/algorithms/jsw_tut_rand.aspx"]Narue's … | |
Re: The for loop on line 55 is actually correct (I think the other poster misread it, it took me a couple of times too). It's legal it just seems a little unorthodox, IMO and definitely hard to read. You don't define the function that it calls yet either. You'd written … | |
Re: There is no null character at the end of a C# string. | |
Re: Add 1.0/1.0+1.0/2.0+... when you do integer division (e.g., 1/2) regardless of the variable the result is going into it still still gets truncated. If you haven't already make sure your result is declared as type double otherwise nothing will work. | |
Re: Can you post more of your class and perhaps a few lines of your text file? It's not readily apparent (at least not to me anyway) what the problem is from the bit you posted. | |
Re: Your method fireQuestion is inherited (publicly) from the base class so you don't need to redeclare it on line 96, it's already a part of your methods in the derived class. In order to call it you need [icode] aColstudent->fireQuestion(mystring,20,0.5,10,20); [/icode] anytime after line 129 (I have no clue what … | |
Re: I'm assuming x1 thru x5 are your data points? The definition of the standard deviation involves first finding the mean of the values. Then find the variance by summing (the difference between data point i and the mean)^2 divided by either the number of values (for an entire population) or … | |
Re: [code] if(name==s[0-4]) <-------?? { string name="******"; } [/code] Creative syntax? How about a for loop: [code] for (int i = 0;i<4;i++) { if(name == s[i]) name = "**********"; } [/code] if you pass in name by reference you will get the change otherwise how is your new name going to … | |
Re: [quote] If element of A is proper [/quote] What is your definition of a "proper" element? | |
Re: Check out [URL="http://stackoverflow.com/questions/236129/c-how-to-split-a-string"]this thread[/URL]. It's not exactly what you want but it gives some good ideas of how to roll your own. | |
Re: The key to this situation is that even when you are not using getchar within a loop the extra '\n' is still in the input stream. Since you are not accessing the stream again it just becomes a distant "memory" as your program finishes. Compare that to when you are … | |
Re: [icode] #include <ctime>[/icode] Then anytime before you use rand put this statement into your program once: [icode] srand((unsigned)time(0));[/icode] This gives rand a seed based on the current time. | |
Re: If blocks is an int array, can't you just change line 8 to: [icode]readLevel >>blocks[rows][cols];[/icode] As long as your files are laid out in a logical manner e.g., [code] 0 1 2 3 4 5 6 7 [/code] it should work |
The End.