419 Posted Topics

Member Avatar for shmamy

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() …

Member Avatar for shmamy
0
740
Member Avatar for Braindead90

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 …

Member Avatar for sfuo
0
259
Member Avatar for Raim

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 …

Member Avatar for Raim
0
425
Member Avatar for myrongainz

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 >> …

Member Avatar for sfuo
0
2K
Member Avatar for bwill31

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().

Member Avatar for bwill31
0
473
Member Avatar for AlvinLiu

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.

Member Avatar for AlvinLiu
0
189
Member Avatar for Tom_Weston

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 …

Member Avatar for Tom_Weston
0
112
Member Avatar for pce369

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 …

Member Avatar for pce369
0
92
Member Avatar for icebirdy

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 …

Member Avatar for sfuo
0
148
Member Avatar for scobi

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.

Member Avatar for scobi
0
309
Member Avatar for brainfo

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.

Member Avatar for nightcrew
0
147
Member Avatar for Macilath

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 …

Member Avatar for Macilath
0
690
Member Avatar for pce369

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 …

Member Avatar for pce369
-1
263
Member Avatar for skylinedrifter

To display the value of X you need to put [CODE]cout << X << endl;[/CODE] after X is calculated.

Member Avatar for brainfo
0
143
Member Avatar for Adam Ma

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 > …

Member Avatar for cherrymae.calma
0
167
Member Avatar for dan_code_guru

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 …

Member Avatar for sfuo
0
252
Member Avatar for glut

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 …

Member Avatar for sfuo
0
212
Member Avatar for Jiggle

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 …

Member Avatar for Jiggle
0
228
Member Avatar for Labdabeta

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.

Member Avatar for jwenting
0
156
Member Avatar for David321

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 …

Member Avatar for raptr_dflo
0
668
Member Avatar for Heioingi

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 …

Member Avatar for Heioingi
0
1K
Member Avatar for Mark198995

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].

Member Avatar for Mark198995
0
153
Member Avatar for coolbeanbob

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]

Member Avatar for sfuo
0
94
Member Avatar for Mahesha999

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 …

Member Avatar for Mahesha999
0
143
Member Avatar for evilguyme

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 …

Member Avatar for evilguyme
0
98
Member Avatar for coder_naive

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 …

Member Avatar for coder_naive
0
159
Member Avatar for evilguyme

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 …

Member Avatar for evilguyme
0
140
Member Avatar for evilguyme

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 …

Member Avatar for evilguyme
0
121
Member Avatar for termin8tor

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 << …

Member Avatar for termin8tor
0
275
Member Avatar for evilguyme

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 = …

Member Avatar for evilguyme
0
152
Member Avatar for nuclear

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().

Member Avatar for nuclear
0
178
Member Avatar for clyo cleopas

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. …

Member Avatar for sfuo
0
114
Member Avatar for L3gacy

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 …

Member Avatar for L3gacy
0
250
Member Avatar for creekist

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.

Member Avatar for gusano79
0
109
Member Avatar for Cross213

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 { …

Member Avatar for Cross213
0
854
Member Avatar for rayden150

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 …

Member Avatar for Ancient Dragon
0
298
Member Avatar for arj'89

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 …

Member Avatar for arj'89
0
1K
Member Avatar for jjyuyujj

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.

Member Avatar for pseudorandom21
0
284
Member Avatar for 4everct01

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.

Member Avatar for 4everct01
0
463
Member Avatar for arbeeorlar gold

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 …

Member Avatar for sfuo
0
87
Member Avatar for Zvjezdan23

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.

Member Avatar for sfuo
0
187
Member Avatar for mridontknow

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> …

Member Avatar for sfuo
0
133
Member Avatar for Mast3r67

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].

Member Avatar for sfuo
0
109
Member Avatar for Kerlix

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 …

Member Avatar for Kerlix
0
291
Member Avatar for MareoRaft

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]

Member Avatar for MareoRaft
0
201
Member Avatar for ari$av3s

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 …

Member Avatar for Narue
0
150
Member Avatar for treepig

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 == …

Member Avatar for danb737
0
678
Member Avatar for ben1996123

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 …

Member Avatar for WaltP
0
236
Member Avatar for ordinary jam

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 …

Member Avatar for mrnutty
1
1K
Member Avatar for vincenzorm117

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) { …

Member Avatar for Narue
0
203

The End.