If you could zip it and post it here (with manage attachments) then I could open it and see what is wrong.
ineedsomehelp:3 commented: Very informative :) +0
If you could zip it and post it here (with manage attachments) then I could open it and see what is wrong.
I copied your source code and it runs fine after taking the semi-colons out.
Can you zip up the source files and the .sln, .vcxproj files? It should only be a few KB in size.
You have a problem with the CreateWindowEx() function because your #define statements at the top have semi-colons at the end of them, and they are not supposed to have that. The preprocessor takes your defines and pretty much uses find-replace on your code then processes it. So your CreateWindowEx() would look like
hWnd = CreateWindowEx(NULL, L"WindowClass1", L"Input Test", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640;, 480;, NULL, NULL, hInstance, NULL);
Notice the ';'s that aren't supposed to be there.
Might be because you do not have the right libraries linked or your settings under 'Project > "ProjectName" Properties... > Configuration Properties > Linker > System > SubSystem' might be set to 'Console' rather than 'Windows'.
You will have to show a lot more source code than that if you want a real answer.
What type is WINDOW_TITLE? All of those syntax errors could be caused by anything, especially after looking at how you were trying to assign an array from before.
If I had to guess I'd say that you haven't linked any libraries to your project and when you fixed that one error it found even more, so it didn't break your program it just showed you the other bunch of errors you have.
To link the libraries to your project go to 'Project > "ProjectName" Properties...', expand 'Configuration Properties', expand 'Linker' and select 'Input'. Under 'Additional Dependencies' you should have nothing but you need some of the default windows ones in order to use the functions above. By default if you make a Win32 console or window project you should have 'kernel32.lib, user32.lib, gdi32.lib, winspool.lib, comdlg32.lib, advapi32.lib, shell32.lib, ole32.lib, oleaut32.lib, uuid.lib, odbc32.lib, odbccp32.lib', however you should only need the first three listed to operate.
The above libs are for the Windows functions, so you will need to add the ones for DirectX (which I do not know what ones you need since I use OpenGL) and whatever other libraries you are using.
You can also add more search directories for the libraries so you do not need to place them all in the Visual Studio lib folder. This is done by selecting 'General' instead of 'Input' and then selecting 'Additional Library Directories' where you just input the path of the folder containing the lib files you want to use.
I'm not 100% sure why you are making a 100 element array to hold 24 indices. Also you are trying to treat an array like a function or something, but it is incorrect.
There are a few ways of doing this but here is the way I think you would want it
short indices[] =
{
0,1,2,
2,1,3,
4,5,6,
6,5,7,
8,9,10,
10,9,11,
12,13,14,
14,13,15
};
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 me a value of 0x0400 whereas Visual Studio is giving me 0x0601.
The solution to this is to manually define WINVER and _WIN32_WINNT to 0x0601, install the latest version of MinGW (manually, because I tried the automatic installer and it didn't seem to do anything) or convert to the darkside and use Visual Studio.
If you are going to do some game development (I am assuming you are because you are playing around with DirectX) I would suggest using Visual Studio because I have ran into many problems trying to get stuff working with MinGW (NVIDIA PhysX SDK couldn't find lots of stuff).
He is lucky that this works. The reason it does is because when you declare an array the last element is automatically set to NULL (which is 0). Then you use getline() which extracts n-1 characters and adds a NULL at index n. So now you have two NULL characters in a row. Then you come to the while loop that checks element 50 (which is NULL) and that is less than 100 and then you increment the 50'th element by one each time. If you did not use getline() then you would have junk being printed out after the name you entered if the name was as long as the array was. This is because you are overwriting the original NULL character that the array created when the array is being made.
The "proper" (because there are many ways to do this) way of doing this is to use a for() loop that uses an integer to count to 100.
#include <iostream>
#include <string>
using namespace std;
int main ()
{
char name[50];
cout << "Insert Name" << '\n';
cin.getline(name, 50);
for( int i = 0; i < 100; i++ )
{
cout << name << '\n';
}
return 0;
}
I would really not recommend doing what you did because you might not be running into problems with it now, but something will happen if you do not use getline() or if you use getline() with an extraction size of your arraysize + 1.
You put
cout << name << endl;
inside your loop.
I would recommend that you go through that tutorial that I linked you and you try to figure out what is going on.
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 recalculates you have to check against all those objects to see if you are touching them. What you should do is divide those 50 platforms into 4 nodes. Then divide each node into another 4 trees until you are down to a reasonable amount of objects in each node. When you load in your level you will do a one time check to set all the platforms into these nodes and then you do not need to move them around again.
On each recalculation of the scene you will check your stick man's box against each node and then you only need to check collision/draw the objects that might be being touched/displayed.
I made a tile game that did not use "sectors" and it lagged because it had to constantly check against hundreds of tiles on each recalculation. Then I modified the game to use sectors so it was only checking against a few tiles each time.
You cannot use platClip[j].w directly because that is not what it is called.
You have declared levelOnePlatform in the global scope and it is usable by everything.
So if you want to access platClip[j].w you need to put it in a loop so you can iterate through each element and use the name levelOnePlatform because that is what the name of the variable in the global scope is.
If I were you I would place the clips for the player within the stick class and the clips for the platform in the platform class. This way it is more like an object because those attributes belong to that class.
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?
struct SDL_Rect //I made this because I didn't want to include all the SDL stuff
{
int x, y, w, h;
};
class Platform
{
int numClips;
SDL_Rect *clips;
public:
Platform()
{
numClips = 50; //so you can know how many clips you have externally rather than hardcoding all throughout your game
clips = new SDL_Rect[numClips]; //create 50 clips
}
SDL_Rect *getClips()
{
return clips; //returns pointer to the first clip
}
int getNumClips()
{
return numClips;
}
~Platform()
{
delete clips;
clips = 0;
}
};
bool check_collision(Platform B)
{
int leftB;
for( int i = 0; i < B.getNumClips(); i++ )
{
leftB = B.getClips()[i].x;
}
return true;
}
int main()
{
Platform A;
check_collision(A);
return 0;
}
You can use a virtual function to print the info for that specific class type.
#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 << endl << "ISBN: " << ISBN << endl << endl;
}
protected:
string title, ISBN;
};
class Publication: public Book
{
public:
Publication(){};
Publication( string t, string i, string p )
{
title = t;
ISBN = i;
publisher = p;
}
void PrintInfo()
{
cout << "Title: " << title << endl << "ISBN: " << ISBN << endl << "Publisher: " << publisher << endl << endl;
}
protected:
string publisher;
};
int main()
{
list<Book*> books;
Publication *tmpPublication = new Publication("How to Get Published", "123456789", "McGoodBooks");
books.push_back(tmpPublication);
Book *tmpBook = new Book("The Big Book", "987654321");
books.push_back(tmpBook);
//print book info
for( list<Book*>::iterator i = books.begin(); i != books.end(); i++ )
{
(*i)->PrintInfo();
}
//delete all books from memory
while( books.size() != 0 )
{
delete books.back();
books.pop_back();
}
return 0;
}
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 the only problem since I have no images and I don't really wanna re-tab all your code each time you post, is that you have SDL_Rect levelOnePlatform[1];
when you should have it with a size of 50 since that is what you are passing into it when you try clipping it.
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
x = 0;
y = 0;
frame = 0;
so that it modifies the stick's variables.
If you cant get your debugger working then just enable the console window and use cout. Or if you are using visual studio and for whatever reason the console window doesn't wanna show up, you can use fstream and write to a file. Because I ran your code with outputs and saw that x and y were huge values which normally means that they are uninitialized.
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. In this case the condition is when the user puts in valid numbers (so change the condition in the loop to catch bad input).
You are passing variables into inputAndValidate() by value and returning nothing, this means that this function does nothing. To fix this pass values in by reference inputAndValidate(int&, int&, int&) similar to what you have already for other functions that also do nothing.
Both functions convertToMinutes() and convertBackToTime() pass values by reference but do not modify them at all. These functions make variables, return nothing and do nothing.
The calcCharge() function does not need to pass any values by reference and you do not need to pass the variable charge into it since you are returning a double.
I would recommend commenting out each function in main() and getting them to work as intended one by one, then getting them to work together.
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().
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 code as a base.
#include <iostream>
#include <stdio.h>
#include <windows.h>
#include <time.h>
using namespace std;
#define MS_IN_HR 3600000
#define MS_IN_MIN 60000
#define MS_IN_SEC 1000
int main()
{
int m,s,h,ms;
time_t totalMS = 0, timeLeft;
cout << "A COUNTDOWN TIMER" << endl;
cout << "enter time in hours here" << endl;
cin >> h;
totalMS += h*MS_IN_HR;
cout << "enter time in minutes here " << endl;
cin >> m;
totalMS += m*MS_IN_MIN;
cout << "enter time in seconds here" << endl;
cin >> s;
totalMS += s*MS_IN_SEC;
cout << "enter time in milliseconds here" << endl;
cin >> ms;
totalMS += ms;
system("PAUSE"); //people will hate you for using PAUSE but you are already using CLS
totalMS += clock();
cout << " A COUNTDOWN TIMER" << endl;
cout << "time remaining" << endl;
cout << "hours: " << h << "mins: " << m << " secs: " << s << " milli: " << ms << endl;
while(clock() < totalMS)
{
timeLeft = totalMS - clock();
system("cls");
cout << timeLeft/MS_IN_HR << " :hours " << (timeLeft%MS_IN_HR)/MS_IN_MIN << " :mins " << ((timeLeft%MS_IN_HR)%MS_IN_MIN)/MS_IN_SEC << " :secs " << (((timeLeft%MS_IN_HR)%MS_IN_MIN)%MS_IN_SEC) << " :milli" << endl;
}
system("cls");
cout …
If you scroll to the bottom of that website you linked you will see unsetf().
Here is an example
#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;
}
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 lines of code I use for getting the fullscreen window size.
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
int CDECL MessageBoxPrintf (TCHAR * szCaption, TCHAR * szFormat, ...)
{
TCHAR szBuffer [1024];
va_list pArgList;
va_start (pArgList, szFormat);
_vsntprintf_s (szBuffer, sizeof(szBuffer) / sizeof(TCHAR),
szFormat, pArgList);
va_end(pArgList);
return MessageBox (NULL, szBuffer, szCaption, 0);
}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
int cxScreen, cyScreen;
//handles for desktop
HWND hDesktopWnd;
HDC hDesktopDC;
hDesktopWnd = GetDesktopWindow();
hDesktopDC = GetDC(hDesktopWnd);
cxScreen = GetDeviceCaps(hDesktopDC, HORZRES);
cyScreen = GetDeviceCaps(hDesktopDC, VERTRES);
ReleaseDC( hDesktopWnd, hDesktopDC );
MessageBoxPrintf (TEXT ("Screen Resolution"),
TEXT ("The screen is %i pixels by %i pixels high."
,cxScren, cyScreen));
return 0;
}
I actually started with C++ so I learned from http://www.cplusplus.com/doc/tutorial/ but learning loops, variables and arrays is common between the two of them.
If you wanna store the names like a = ant
you should use strings (char*).
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#define sz 12
int main()
{
int i, j;
char* animals[sz] = {"ant", "bear", "cat", "dog", "emu", "goat", "lizard", "monkey", "parrot", "rabbit", "snake", "tiger"};
char* chosen[4] = {"", "", "", ""};
srand(time(NULL));
for( i = 0; i < 4; i++ )
{
chosen[i] = animals[rand()%12];
for( j = 0; j < 4; j++ )
if( strcmp(chosen[i], chosen[j]) == 0 && j != i ) //checks to see if the animal picked is unique
{
i--; //if not decrease counter so it overwrites the last animal
break;
}
}
for( i = 0; i < 4; i++ )
{
printf("%c - ", chosen[i][0]); //for first letter of animals name
printf("%s ", chosen[i]); //for whole name of animal
}
printf("\n");
return 0;
}
You can try to use a math function like y=2^(x/3) set your x and y coordinates for the ramp (it would look like this).
The function looks like a ramp and depending on the increment for x you can make it more or less smooth and you can change the length of the ramp by setting the upper bound of the for() loop used to make the ramp.
You can do it with a bunch of if/else statements like this
#include <iostream>
using namespace std;
int main()
{
string encoded = "45323456", decoded = "", encodedPart;
for( unsigned int i = 0; i < encoded.length(); i+=2 )
{
encodedPart = encoded.substr(i, 2);
if( encodedPart == "45" )
decoded += 'd';
else if( encodedPart == "32" )
decoded += 'o';
else if( encodedPart == "34" )
decoded += 'v';
else if( encodedPart == "56" )
decoded += 'e';
else
; //this does nothing but without it you will get an error since there is nothing
}
cout << decoded << endl;
return 0;
}
I wouldn't really say the map is over your head since just an array but with custom indexes (some languages call them dictionaries because that is pretty much how they are used).
In map<string, char>
the index is a string and what gets held at that index is a char.
Its almost exactly the same as if you had an array of characters except for it is indexed by a string and it is a dynamic array rather than a static one.
You could use a map to help decode the message.
#include <iostream>
#include <map>
using namespace std;
int main()
{
map<string, char> cipher;
cipher["45"] = 'd';
cipher["32"] = 'o';
cipher["34"] = 'v';
cipher["56"] = 'e';
string encoded = "45323456", decoded = "";
for( unsigned int i = 0; i < encoded.length(); i+=2 )
decoded += cipher[encoded.substr(i, 2)];
cout << decoded << endl;
return 0;
}
On line 22 you are setting space to 1 when you increase the length. I'm pretty sure if you take that line out you should be good.
I was wondering why you called it CSV since there wasnt a comma in it. Then I refreshed the page a few times and you edited your post! I have no idea how you were kinda thinking you wanted the data to be stored so I made a DATA structure to hold the strings and numbers.
I'm sure you can think up a better way to output the data if you wanted to.
#include <iostream>
#include <fstream>
#include <vector>
#include <sstream>
using namespace std;
struct DATA
{
string day, month;
int date;
string time, timezone;
int year;
void Display()
{
cout << day << " " << month << " " << date << " " << time << " " << timezone << " " << year;
}
};
int main()
{
string line;
vector<DATA> DataStore;
ifstream file("test.txt");
while( getline(file,line, ',') )
{
stringstream lineStream(line);
DATA element;
lineStream >> element.day >> element.month >> element.date >> element.time >> element.timezone >> element.year;
DataStore.push_back(element);
getline(file,line);
}
for( unsigned int i = 0; i < DataStore.size(); i++ )
{
DataStore[i].Display();
cout << endl;
}
file.close();
return 0;
}
Can you post a sample input? I cant visualize this at all.
This is what I'm seeing
abc123,12345
def456,94032
....
Is that not what you asked above?
How can I store the data from column one only?
In your while() loop condition that actually pulls a line out of the file and stores it into line so you are reading every second line with your code. Also you are overwriting your holding variable bit with the 2nd column of information.
The only part that is really different below is the while() loop. Other than that I think its pretty much the same.
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main()
{
string line;
vector<string> DataStore;
ifstream file("test.txt");
while( getline(file,line, ',') )
{
DataStore.push_back(line);
getline(file,line);
}
for( unsigned int i = 0; i < DataStore.size(); i++ )
cout << DataStore[i] << endl;
return 0;
}
The problem is because you are setting your "destination point" on line 26 to invokeX/Y (0,0) and getting the distance from the invoke point (0,0). So either I would delete line 26 and replace destinationPoint on line 35 with pt1.
Here is something I threw together using the code you posted. This is what I think you are trying to do.
Since the distance function is within your class I used the point within the instance with the point passed into the function to determine the distance rather than hard coding 0 (I know that you just did that for testing).
#include <iostream>
#include <cmath>
using namespace std;
double sqr(double x) //made this because I hate using the pow function for powers of 2
{
return x*x;
}
class Point
{
public:
Point();
Point(const double x, const double y);
//Point(Point &otherPoint); //not sure why you are passing reference but left this one out
double getX();
double getY();
void setX(const double X); //undefined/unused in this code
void setY(const double Y); //undefined/unused in this code
void print(); //undefined/unused in this code
double distance(Point destinationPoint);
private: //just fyi this can be up at the top since classes start off private
double _x; //put _'s before the variable name because you
double _y; //had the constructor with the variable names
};
Point::Point()
{
_x = 0;
_y = 0;
}
Point::Point(const double x, const double y)
{
_x = x;
_y = y;
}
double Point::getX()
{
return _x;
}
double Point::getY()
{
return _y;
}
double Point::distance(Point destinationPoint)
{
return sqrt(sqr(destinationPoint.getX() - _x) + sqr(destinationPoint.getY() - _y));
}
int main()
{
Point invoke(0,0);
Point pt1(2,2);
cout << "The distance from invoking point (" << invoke.getX() << "," << invoke.getY() << ")" …
Above you have aPoint being passed into the distance function and you are displaying pt1's x and y values. Do you mean to pass pt1 into the function? Based on the code that you haven shown I cannot see anything else that could be causing the problem.
You have to tell the fstream object that you want to output with it by typing:
fstream out;
out.open("output.txt", fstream::out);
You can go into your project settings and make it a Win32 Windows application and that will hide the console window.
This is a basic version of what I think you are trying to do.
#include <iostream>
using namespace std;
class DRAGON
{
public:
int hp;
int def;
int atk;
bool alive;
DRAGON();
int getHealth();
void setHealth(int);
};
DRAGON::DRAGON()
{
hp = 50;
def = 2;
atk = 10;
alive = true;
}
int DRAGON::getHealth()
{
return hp;
}
void DRAGON::setHealth( int dmg )
{
if( hp - dmg < 0 )
hp = 0;
else
hp -= dmg;
}
void attackPTR( DRAGON *d1, DRAGON *d2 )
{
d1->setHealth(d2->atk - d1->def);
d2->setHealth(d1->atk - d2->def);
}
void attackREF( DRAGON &d1, DRAGON &d2 )
{
d1.setHealth(d2.atk - d1.def);
d2.setHealth(d1.atk - d2.def);
}
int main()
{
DRAGON d1, d2;
attackPTR( &d1, &d2 ); //using pointer attack function
cout << "d1: " << d1.getHealth() << " d2: " << d2.getHealth() << endl;
attackREF(d1, d2); //using reference attack function
cout << "d1: " << d1.getHealth() << " d2: " << d2.getHealth() << endl;
return 0;
}
I put in both pointer and ref attack functions to show that they do the exact same thing but by reference makes it so you dont have to keep putting in the arrows and you do not have to pass by reference in the function usage.
I would try to use your code to show you an example but you are showing code that doesnt have to be posted for your problem and now showing parts that are key to finding the error.
And by the looks …
void sethpmax(){hpmax = lvlhp[lvl - 1];};
void setexpmax(){expmax = lvlexp[lvl - 1];};Random arrays assigned to int? This should not even compile.
This looks fine to me. Hes assigning the units health to whatever is at lvlhp[lvl-1] is. So if the guy is level 5 it would be lvlhp[5-1] or lvlhp[4]. That makes perfect sense.
It will only output the last letter because a char type is only one character. You can use a string and add the letters onto that then output the word with outFile.
Put one do()while() within the other do()while() so it keeps looping unless you are done your game loop and when you do not want to play again.
Doing this you will want to have two variables instead of having both as done.
Did you throw in a cout << y << endl;
at the end?
lines 21 and 22 are from your original code. Delete them if you do not want to see your inputs every time.
Post what you put in. I tested this before I posted.
You can use the accumulate function like jonsca said or you can just use a for() loop and add them all up. Since you didn't know how to add a vector up I would recommend using this method so you can figure out what is going on then maybe use the accumulate function later.
#include<iostream>
#include<vector>
using namespace std;
typedef vector<int> VECTORINT;
int main()
{
VECTORINT Vectorul;
int x;
int num;
int y = 0; //sum?
cin >> num; //the number of numbers that must be entered
for( int i = 0; i < num; i++ )
{
cin >> x;
y += x; //either add them here
Vectorul.push_back(x);
for( int j = 0; j < Vectorul.size(); j++ ) //do not nest for() loops with the same variable
cout << Vectorul[j] << endl; //seems kinda pointless and just clutters the input/output
}
for( int i = 0; i < Vectorul.size(); i++ )
y += Vectorul[i]; //or add them here BUT do not include both of these sections
system("pause");
return 0;
}
You could just create an int called sum with an initial value of 0 and then make a for() loop just add all the elements to sum one by one until the end of the vector.
Like 4olkata said use cin >> n1 >> n2 >> n3;
because the comma does not work like that in C++.
Also abs(n1)
does nothing because that will just return the absolute value of n1. You want n1 = abs(n1);
because this will assign n1 to the absolute value of n1.
Then just to drop one check for the equilateral you only need if( n1 == n2 && n1 == n3 )
because that would mean that n2 and n3 are equal also.
Since he wants it 1-99 you would divide by 99 not 100.
edit ** red goose is right this would give 1 for 99 and anything above. I don't know what I was thinking =)
From what you posted there are 2 problems.
Line 54 you need it to be else if not just else.
You cannot use else then a statement else acts as an "if the statement is not true do this instead" but else if checks the statement for another condition if the first one fails.
Then Line 56 you have mistyped first_digit.
You can make it as one process, just create a console application then put the window code into it and run it. You will see a the console window and a window pop up. All cin/cout usage will go to the console window and if you have your program/inputs set up properly you are going to be able to use that input to manipulate your window.
You can use the % (mod) operator to get the remainder of one number divided by another.
ie
72 % 10 = 2 <--- your first digit