419 Posted Topics
Re: Do you have to use substr()? Because this can be easily done with a for() loop. [CODE]#include <iostream> using namespace std; int main() { string str; bool palindrome = true; cout << "Please enter a sentence: "; getline(cin, str); for( int i = 0, j = (int)str.length()-1; (i < (int)str.length() … | |
Re: I wrote this linked list a while ago. After reading yours for a bit I went back and modified mine to use templates and used your names. You can take a look at this and use what you want. It has four functions: Add() which appends a node to the … | |
![]() | Re: I have never made a Windows Form Application before but I just made one out of the template and threw [ICODE]#include <cmath>[/ICODE] (you should use cmath not math.h in C++) at the top and it compiled without a problem, since as I suspected just C++ with a big library attached … ![]() |
Re: I would use two for() loops. You can use a while() loop but I tend to avoid them when you want to count through a range of values. [CODE]#include <iostream> using namespace std; int main() { int num1, num2; cout << "Enter a positive integer: " << endl; cin >> … | |
Re: This compiled fine for me other than the fact I had to include cstdlib (for system()) and cstring (for strcmp() and strcpy()) and I had to change strcpy_s() to strcpy(). | |
Re: Can you post all the code? You just posted up the Calculator source file and are missing the myComplex class all together and the main function. | |
Re: That is because cin is looking for a whitespace between each input(' ' or '\n'). So if you typed "much . love" it would work the way you have it set up now, but if you typed "much.love" then sztext1 would be "much.love" and it doesn't show Works... because it … | |
Re: Your function displayResults() has no idea that myfile exists. There are a few things you can do. You can declare ofstream myfile as global, pass it through the function as a parameter or declare it within the function. If you are not writing to the file anywhere else but within … | |
Re: This is one of the most basic examples I can come up with that includes exactly what you asked. [CODE]#include <iostream> using namespace std; class ClassA { int a, b; public: ClassA(){}; //need a default constructor ClassA(int _a, int _b) { a = _a; b = _b; } }; class … | |
Re: fstream is part of the std namespace. So either put [ICODE]using namespace std;[/ICODE] or [CODE]using std::fstream;[/CODE] along with others that you need to use. | |
Re: You can't. If your compiler supports it then you can have a pause when it is ran through the compiler but no program runs and pauses at the end without being forced to. | |
Re: One big thing you have to understand is that a function (ie main()) is not a class. Classes hold variables and functions which can be accessed/used via the "dot" (.) operator. Here is an example of an Event_Time class that prints out the current date and time when you call … | |
Re: After going through this it is clear that you do not understand a few things. #1 you have to name your arguments/parameters for your functions (except for the function proto-types) #2 you are using uninitialized variables in calculations (this is why you are getting 0) #3 you are not passing … | |
Re: To display the value of X you need to put [CODE]cout << X << endl;[/CODE] after X is calculated. | |
Re: This took a bit more than 30 secs but it isn't full of errors and uses whitespace so you can actually see what is going on. [CODE]#include <iostream> using namespace std; int main() { int num; cout << "please enter a number" << endl; cin >> num; if( num > … | |
Re: The issue is because the value of _WIN32_WINNT is below 0x0501. When I compile in Code::Blocks I get the same problem, but if I compile in Visual Studio C++ then I no longer have the problem. This is because the version of MinGW that comes with Code::Blocks is giving _WIN32_WINNT … | |
Re: Are you adding the libraries libopengl32.a and libglu32.a? GLUT is a toolkit to try and make it easier to create OpenGL applications, so adding glu.h and gl.h would not resolve the problem with the missing header. Plus GLUT has been discontinued so if you want to use it still you … | |
Re: SDL_Surface is just a structure that holds the needed information for drawing. TTF_RenderText_Solid() will just return a pointer to a block of memory where a SDL_Surface is being stored and then you make a pointer point to the memory location of that object so then you can draw it to … | |
Re: Why don't you get the free trial, play around with it and see what you can do, then buy it. And I'm 100% sure it exports model files (with all the vertex info) rather than images. Not sure why you would think that it exports just images. | |
Re: I think your method in general is the problem. I looked up Knight's Tour in Wikipedia and read the [URL="http://en.wikipedia.org/wiki/Knight%27s_tour#Warnsdorff.27s_rule"]Wansdorff[/URL] section and came up with my own code. This method is really easy to implement because I had never heard of this Knights Tour puzzle and I put this together … | |
Re: You needed to think this through a little bit more before trying to put all the situations of the program in together. You need to make the program based off the words used in the assignment text. When it says minimum payment of $2 you should start the fee at … | |
Re: What you are looking for is a for() loop Take a look here at control statements (including the for() loop) [URL="http://www.cplusplus.com/doc/tutorial/control/"]here[/URL]. | |
Re: You would have to have your while() as [CODE]while(random != 0 || random != 1);[/CODE] but this wouldnt work as you want it to. You need to use and (&&) [CODE]while(random != 0 && random != 1);[/CODE] | |
Re: Not 100% sure how to explain how it holds all the memory but I think this is what you are aiming for. When I compiled your code I was getting warning and it crashed on run-time. [CODE]#include <stdio.h> #include <stdlib.h> int main() { char *dic[][40] = { {"Atlas", "A volume … | |
Re: For a 2D game you should look into quadtrees (octrees for 3D games). What this does is it helps you manage how many objects you are checking collision against or drawing on each collision check and draw. Since you have 50 platforms in level 1 and every time the scene … | |
Re: That is because structures and functions are completely different. Structures are blocks of data that are made up of primitive data types (int, char, float) or other structures and you cannot set default values to them within the structure. However you can make a function to set the values or … | |
Re: I can't really tell what you are trying to do since the code on google docs is really old (still has errors from last post). Is this along the lines of what you are trying to accomplish? [CODE]struct SDL_Rect //I made this because I didn't want to include all the … | |
Re: If you want us to try to compile your code then you should post it in code tags in here because most of the formatting is lost when I try to copy paste it from the rtf file. The big thing that I see, and I'm not sure if its … | |
Re: You can use a virtual function to print the info for that specific class type. [CODE]#include <iostream> #include <list> using namespace std; class Book { public: Book(){}; Book(string t, string i) { title = t; ISBN = i; } virtual void PrintInfo() { cout << "Title: " << title << … | |
Re: The problem is in the constructor. You are declaring three new integers (x, y and frame). After the constructor is done those three do not exist and stick::x, stick::y, stick::frame are not modified at all. So what you need to do is remove int from in front of [CODE]x = … | |
Re: Your Load_image() function is always gonna return 0. On line 13 of what you posted above delete SDL_Surface* because it is making a new variable with the same name as you have out of the if() statement and is not changing the value outside of the if(). | |
Re: You have many errors in your code, the loop ending is just one of them. In order for the loop to end the way it is right now the person has to enter numbers out of range. A while loop will go for as long as the condition is met. … | |
Re: Pretty sure what you just posted is trying to get the size of the window that was made by the running program. You haven't made a window so it is going to be 0 by 0 in size. I can't compile what you have but I just threw in the … | |
Re: Don't you have the x y z position and x y z rotation of your character (and gun)? Then just apply these to the camera with the offset so it is looking from the right height. That is if this is for a FPS. | |
Re: This is the first Linked List I have ever written but is this what you are trying to do? The Change() function searches the list for an entry with the same name and then asks to change the age of the person. [CODE]#include <iostream> using namespace std; struct Node { … | |
Re: I would really suggest not using C and C++ the way you are. You have outputs using cout and printf(). Here is a C++ convert. [CODE]#include <iostream> #include <fstream> using namespace std; struct patient { string name; string blood; string height; string Ssn; }; bool I_code3(string name, patient &ab); //Function … | |
Re: You have more problems than just lines 5,6, 7. To fix lines 5, 6, 7 make them pointers and then use calloc() to allocate blocks of memory for them after figuring out how many students you are gonna have input for. You were putting ';' at the end of the … | |
Re: Does your PlaySound() function also load the sound file into memory? If it does then you should load them before then use that to just play them. | |
Re: Why don't you make your printDeck() function and not display the cards within the shuffle function? This way you will always print out each card once. | |
Re: There are a few things that you need to do. The main ones are formatting and basic syntax. I would suggest going over the tutorial at [URL="http://www.cplusplus.com/doc/tutorial/"]http://www.cplusplus.com/doc/tutorial/[/URL]. [CODE]// multiplication #include <iostream> //use iostream (iostream.h should not be used any more) using namespace std; //can use this or add std:: infront … | |
Re: On line 123 make it a friend function. [CODE]inline friend Vector3 operator *(float k, const Vector3 &v)[/CODE] This won't work if you have your class defined within main() but I'm not too sure why you have it like that in the first place. | |
Re: There are lots of ways to fix up your code, depending on if you want to pass by reference or just return a vector and copy it. This is creating a vector in function1() and returning it. [CODE]#include <iostream> #include <vector> #include <string> using namespace std; vector<string> function1() { vector<string> … | |
Re: Not sure if you have figured this out yet or not. The problem is because you are calling the function [ICODE]SDL_DisplayFormat()[/ICODE] before [ICODE]SDL_Init(SDL_INIT_EVERYTHING)[/ICODE]. The fix to this would be to move [ICODE]load_files()[/ICODE] below [ICODE]SDL_Init(SDL_INIT_EVERYTHING)[/ICODE]. | |
Re: You are using sleep() functions that make the program sleep for 13 hrs 53 min and a few seconds. What I would suggest is using the clock() function to get the time elapsed since the start of the program in milliseconds. Here is something that I put together using your … | |
Re: If you scroll to the bottom of that website you linked you will see unsetf(). Here is an example [CODE]#include <iostream> using namespace std; int main() { cout.setf(ios_base::fixed); cout << 100.1 << endl; //with fixed cout.unsetf(ios_base::fixed); cout << 100.2 << endl; //without fixed return 0; } [/CODE] | |
Re: If you want to use arguments then you need to use main() with argc and **argv. argc is the counter of how many arguments that are passed in to the program (it is 1 with no additional arguments passed because it passes it's own path by default). argv is the … | |
Re: Here is how you could initialize and draw the board. [CODE]TicTacToe::TicTacToe() { player = 'O'; for( int i = 0; i < 9; i++ ) board[i] = i+'1'; } void TicTacToe::displayBoard() { // Your implementation here... for (int i = 0; i < 9; i++) if( (i+1) % 3 == … ![]() | |
Re: On line 36 of what you posted you have int [ICODE]askForPlace();[/ICODE] you need to remove "int". When compiling this I got lots of warnings because you have a bunch of functions that are defined to return an int but do not return anything. If you want them to return nothing … | |
Re: You cannot return multiple values at once unless they are bound within a structure or an array (even then you are just returning the place in member where they start). There are two ways that you can do this (there are more): 1) Pass values by reference and modify one … | |
Re: Here is a rough example of why you would want to use it. If you comment out [ICODE]fflush(stdin);[/ICODE] then it skips asking for input every second one, but with it you get asked every time. [CODE]#include <stdio.h> #include <stdlib.h> int main() { int i = 1; char input; while(1) { … |
The End.