419 Posted Topics
Re: Here is a thread that talks about the floating point types [URL="http://www.daniweb.com/forums/thread176435.html"]here[/URL]. And if you want the decimals to show you can use the <iomanip> header [ICODE]cout << setprecision(5) << fixed;[/ICODE] You can check out [URL="http://www.cplusplus.com/reference/iostream/manipulators/"]this[/URL] to get more manipulators and see what the ones I posted do. | |
Re: Missed the end quote so that would return an error. | |
Re: You have lots of unused variables and in here you had 2 for-loops that were not needed. [CODE]cout<<"Starting balance for Account 1: "<<banker1.accountBalance<<endl; cout<<"Starting balance for Account 2: "<<banker2.accountBalance<<endl; double newMonthlyBalance1 = banker1.accountBalance; double newMonthlyBalance2 = banker2.accountBalance; for(year = 1; year <= numberOfYears; year ++) { cout<<"Year "<<year<<" "<<endl; for(month … | |
Re: Make sure you have the header <iostream> and I'm pretty sure its calc.exe not calculator.exe unless that is the name of your program. Also [ICODE]if (operation != '+' || '-' || '*' || '/' )[/ICODE] Does not do what you think it will. You want to have [ICODE]if( operation != … | |
Re: Here is something I threw together really quick using a vector and a structure. Shouldn't be that hard to transfer it over to using a linked list. [CODE]#include <iostream> #include <vector> using namespace std; struct monomial { int coeff; int exp; }; int main() { int numCoeff = 0; cout … | |
Re: #1 you misspelled ppoly1 in [ICODE]cout << pploy1->area() << endl;[/ICODE] so that should be giving you an error. In order for the code to work the way you want it to you would need to make a pure virtual function in the class CPolygon: [ICODE]virtual int area() = 0;[/ICODE] By … | |
Re: I just put both files in one for this post. One huge thing you have to think about is how you format your code and variable names especially when you are going to post on a forum asking for help. I tried to clean it up with some white space … | |
Re: I posted a solution in your original thread and what you have there does not do what you think it does. You need to use the new operator since NewArray is being declared locally in your function and therefore is deleted at the end of the function. If you use … | |
Re: Look at your function prototype it does not match your function below. [ICODE]int reverseArray(int, int, int *);[/ICODE] should be [ICODE]int reverseArray(int[5], int, int *);[/ICODE] Edit: or just [ICODE]int reverseArray(int[], int, int *);[/ICODE] | |
Re: @caut_baia - he said the data types that he had to use so I don't think using a structure would be following those guide lines. @op - Not sure if you are allowed to use a pointer but I threw it in with a switch otherwise you would have to … | |
Re: Not sure if you need to use arrays and cstrings for your assignment but in C++ there is a string class and vector class that I think would work way better for this. [CODE]#include <iostream> #include <string> #include <vector> using namespace std; int main() { srand(time(NULL)); //seed random vector<string> article(5); … | |
Re: You do not output an array like that. You have to go through each element and output it. array1 just points to the first element in the memory block. [CODE]for( int i = 0; i < size; i++ ) cout << array1[i] << endl;[/CODE] This should do exactly what you … | |
Re: I haven't ever done this but I know it is called a Singleton. I looked it up on wiki and they have an example there. [URL="http://en.wikipedia.org/wiki/Singleton_pattern#C.2B.2B"]here[/URL] | |
Re: You don't need to make them a string you could just use %10 and /10 to figure out the 1s and 10s digit then add those 2 numbers together to check. Edit: Didn't even read the whole post until after mine and it says right in there how to do … | |
Re: The big problem other than how you are trying to initialize your variables would be the fact that it is dividing by zero. I commented the code where it was wrong. [CODE]void Rational::reduction() { int largest = numerator > denominator ? numerator : denominator; int gcd = 0; for(int loop … | |
Re: I know it is homework and you didn't post what you have but its really simple and if you don't know how to start this then I wouldn't really expect any work done already. [CODE]#include <iostream> using namespace std; int main() { for( int i = 1; i < 10; … | |
Re: You need to store them as characters because you cannot have an integer hold a 50 digit number. And if you try to use a float or double you will lose precision. So store them as a character and come up with function that does math between 2 strings. | |
Re: Recursion is cool but when I was testing out using loops vs it any number 4 and above took longer to calculate when using the recursive function (time taken is not noticeable) and recursion takes up more memory because it keeps adding to the stack. This is the code I … | |
Hey guys I have come up with a solution for the problem I have but I would like to know how I could do this the way I initially had it set up but without the leak of course. vec3f.h [CODE]class vec3f { public: GLfloat _x, _y, _z; vec3f(){}; vec3f( … | |
Re: You should make a variable called playerHand or something that will keep track of what the players current hand is worth. That way you can just add the random integer to it and then make a new random integer while still keeping the value of the players hand. The very … | |
Re: [CODE]void printAllFactors( int in ) { //remove the = if you want it to not show "in" as being a factor for( int i = 1; i <= in; i++ ) //start the counter at 1 and loop it until it reaches the inputted number if( in % i == … | |
Re: Not sure if you want to add the extra number in so you know how long the vector is. Otherwise you would have to read it in and check for the commas. [CODE]#include <iostream> #include <vector> #include <deque> #include <fstream> using namespace std; struct Entry { int addr; int dst; … | |
Re: I would move the camera around when you press the arrow keys and rotate the objects around for when they get turned. I was making a rubik's cube and came across the same problems because if you turn the cube 90 deg on the y axis then when you rotate … | |
Re: I came up with a way to output the characters and semi commented what is going on. [CODE]#include <iostream> using namespace std; int main() { int n; char in[2]; //change to an array (see output) cout << "Enter two characters and an integer: " << flush; cin >> in[0] >> … | |
Re: Yeah it is annoying because the new version of C::B doesn't come with MinGW. Just go to the MinGW website and download the latest version and drop it in your C::B directory. | |
Re: Doesn't 3/12 reduce to 1/4 and 9/12 to 3/4. Also 2/12 reduces to 1/6 not 1/12 (typo I think). | |
Re: I fixed up your if statement at the bottom so if you do not type in y or Y it will end. [CODE]#include <iostream> using namespace std; int main() { cout << "\n\t\tWelcome to Doc's gas figure out thingy!\n"; Car car; bool another = true; while(another) { Car next; next.drive(); … | |
Re: Graphics are just blocks of data that get read in by code and then get displayed using libraries like OpenGL or DirectX or what ever else you choose to use. If you were to do something with graphics I would suggest just making a box that is colored through the … | |
Re: Just need to make a text file called textin.txt with your words and put it in the same directory as your .exe file. [CODE]#include <iostream> #include <fstream> using namespace std; int main() { string line; //to hold the lines read from textin.txt ifstream in("textin.txt"); ofstream out("textout.txt"); while ( getline(in, line) … | |
Re: The values that get passed into that function will be pixel coordinates then the functions would call [ICODE]gluPickMatrix((GLdouble) x, (GLdouble) (viewport[3] -y), 1.0, 1.0, viewport);[/ICODE] where 1.0 and 1.0 is the size I chose of the selection region. Not sure if you know anything about selecting objects in OpenGL but … | |
Re: Isn't that drawing from the point (395,150) to (250, 150)? I've never used this before but if you were to make a 3, 4 ,5 triangle you could probably just go [CODE]graphicsObject->DrawLine( coloredPen, 200, 150, 200, 190 ); graphicsObject->DrawLine( coloredPen, 200, 190, 230, 190 ); graphicsObject->DrawLine( coloredPen, 230, 190, 200, … | |
Re: I stopped using GLUT a while ago but I'm pretty sure you have to set up the projection matrix and all that still. [CODE]void DrawCircle(void) { glViewport(0, 0, (GLsizei) WINDOW_WIDTH, (GLsizei) WINDOW_HEIGHT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60, (GLfloat) WINDOW_WIDTH/ (GLfloat) WINDOW_HEIGHT, 0.1, 60.0); glTranslatef(0.0, 0.0, -10); //move camera back 10 units (so … | |
Re: When you say two different objects same class do you mean [CODE]myClass obj1; myClass obj2;[/CODE] or are they both built off the same class with inheritance? If you have some code showing what you have tried that would be helpful. | |
Re: This is what I noticed when quickly going through your code. [CODE]void AddItem(vector <Inventory> &MyInventory, unsigned &key, int &i) { //change it to &MyInventory instead of *MyInventory since you are going to be changing it like the variable i //this means just pass it in normally and not by reference … | |
Re: Lots of your code did nothing because it was incorrect. I would just use floats because if there are no decimals in the result (ie 5+5 = 10) it will output 10 not 10.0. I used class operators in this but if you want to keep with with pass by … | |
Re: This is a really easy way to do it. Might be an easier/better way but this is what I put together in a few mins. [CODE]#include <iostream> #include <string> using namespace std; int main() { string sean = "hello2"; cout << sean << endl; for( unsigned int i = 0; … | |
Re: I'm not 100% sure why (5/9) is having problems displaying as a double but that is why you are getting a bunch of zeros. [CODE]#include <iostream> #include <iomanip> using namespace std; int main() { float cel = 0; cout << setprecision(1) << fixed; //sets 1 decimal place (fixed makes it … | |
Re: The error you are asking about is not just for dynamic memory it is for any time you try to assign outside of a function. You can declare outside of functions like [ICODE]int *sean = new int;[/ICODE] but [ICODE]sean = new int;[/ICODE] will give you an error because you are … | |
Re: I wouldn't recommend SDL because it may be simple but it is pretty rigid and if you want to give your game to a friend you have to include a whole crap load of dll files to make it work. I prefer using OpenGL for 2D or 3D games but … | |
Re: This thread was dead for 4 years lol. Don't post in old threads as said in the read before posting. | |
Re: First question is have you even made a 2D game before? SDL is "good" because it makes the window, sets pfd, handles keyboard/mouse input and a few other things but I really disliked how you had to carry 50 dll files around with it just so you could have sound … | |
Re: You can look over this and see what is going on but as you will notice I commented in most of the stuff it is missing from being complete. [CODE]#include <iostream> using namespace std; void DisplaySeats( char seats[][4], int rows ) { for( int i = 0; i < rows; … | |
Re: In your calcCelsius() function I don't think that you want the line cin >> cel; since you are displaying it in the next function. This is what makes it seem like it "stops" when really its just waiting for input. | |
So far I have written a program that draws text to the screen and I am able to change the font type but I am unable to change the font size. Here are the 3 main parts of my code that I think you need to see. Font structure: [CODE]typedef … | |
Re: Are we supposed to post the answer we get to double check? I got 6580. ![]() | |
Re: I threw in some ideas quickly so its not just option 1 option 1-a and stuff like that. Most of it is pretty lame but not too much thought went into it. The main things that are being used in here are functions and the switch statement. You can try … | |
Re: a, b and c do not have a value assigned to them and you are using them. I think this is how you want the program structured. Compare what I have to what you have closely because you made many errors and I didn't comment all of them in. [CODE]#include … | |
Re: I learned C++ [URL="http://www.cplusplus.com/doc/tutorial/"]here[/URL] and I still use it website for reference at times. | |
Re: Yeah I switched from Dev-C++ to Code::Blocks when I figured out it was really out of date. Dev-C++ is a pretty nice compiler because everything is pretty easy to use but I suggest you move on sooner before you get too attached. | |
![]() | Re: Not sure why you would store all the values from your array into single ints a-j when you could just use the array and for loops to store the sums into a value. You could use stringstream but if you don't want to include another header file and since the … ![]() |
The End.