Be a Supporter!

C++ Codes Here!

  • 18,663 Views
  • 452 Replies
New Topic Respond to this Topic
Lordfat
Lordfat
  • Member since: May. 30, 2000
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to C++ Codes Here! 2005-02-20 17:38:48 Reply

At 2/18/05 10:43 AM, Kaabi wrote: Can someone find the code for C++ to make a 3d image? I just want to see what the code looks like for something like that.

Haha do you really now? Well unless you want to code your own windows API (which you don't) you'll have to use DirectX or OpenGL. I personally prefer direct3d because it makes a few things easier to do ( it makes other things harder too though). I'll show you something in OpenGL since you can't compile directx without first installing it. Here is the source code to make a pretty rotating triangle in OpenGL: (FYI not my work!)

// GLSAMPLE.CPP
// by Blaine Hodge
//

// Includes

#include <windows.h>
#include <gl/gl.h>

// Function Declarations

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void EnableOpenGL(HWND hWnd, HDC * hDC, HGLRC * hRC);
void DisableOpenGL(HWND hWnd, HDC hDC, HGLRC hRC);

// WinMain

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int iCmdShow)
{
WNDCLASS wc;
HWND hWnd;
HDC hDC;
HGLRC hRC;
MSG msg;
BOOL quit = FALSE;
float theta = 0.0f;

// register window class
wc.style = CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
wc.lpszMenuName = NULL;
wc.lpszClassName = "GLSample";
RegisterClass( &wc );

// create main window
hWnd = CreateWindow(
"GLSample", "OpenGL Sample",
WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
0, 0, 256, 256,
NULL, NULL, hInstance, NULL );

// enable OpenGL for the window
EnableOpenGL( hWnd, &hDC, &hRC );

// program main loop
while ( !quit )
{

// check for messages
if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{

// handle or dispatch messages
if ( msg.message == WM_QUIT )
{
quit = TRUE;
}
else
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}

}
else
{

// OpenGL animation code goes here

glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glClear( GL_COLOR_BUFFER_BIT );

glPushMatrix();
glRotatef( theta, 0.0f, 0.0f, 1.0f );
glBegin( GL_TRIANGLES );
glColor3f( 1.0f, 0.0f, 0.0f ); glVertex2f( 0.0f, 1.0f );
glColor3f( 0.0f, 1.0f, 0.0f ); glVertex2f( 0.87f, -0.5f );
glColor3f( 0.0f, 0.0f, 1.0f ); glVertex2f( -0.87f, -0.5f );
glEnd();
glPopMatrix();

SwapBuffers( hDC );

theta += 1.0f;

}

}

// shutdown OpenGL
DisableOpenGL( hWnd, hDC, hRC );

// destroy the window explicitly
DestroyWindow( hWnd );

return msg.wParam;

}

// Window Procedure

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{

switch (message)
{

case WM_CREATE:
return 0;

case WM_CLOSE:
PostQuitMessage( 0 );
return 0;

case WM_DESTROY:
return 0;

case WM_KEYDOWN:
switch ( wParam )
{

case VK_ESCAPE:
PostQuitMessage(0);
return 0;

}
return 0;

default:
return DefWindowProc( hWnd, message, wParam, lParam );

}

}

// Enable OpenGL

void EnableOpenGL(HWND hWnd, HDC * hDC, HGLRC * hRC)
{
PIXELFORMATDESCRIPTOR pfd;
int format;

// get the device context (DC)
*hDC = GetDC( hWnd );

// set the pixel format for the DC
ZeroMemory( &pfd, sizeof( pfd ) );
pfd.nSize = sizeof( pfd );
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
format = ChoosePixelFormat( *hDC, &pfd );
SetPixelFormat( *hDC, format, &pfd );

// create and enable the render context (RC)
*hRC = wglCreateContext( *hDC );
wglMakeCurrent( *hDC, *hRC );

}

// Disable OpenGL

void DisableOpenGL(HWND hWnd, HDC hDC, HGLRC hRC)
{
wglMakeCurrent( NULL, NULL );
wglDeleteContext( hRC );
ReleaseDC( hWnd, hDC );
}

Phew. Simple right?

Lordfat
Lordfat
  • Member since: May. 30, 2000
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to C++ Codes Here! 2005-02-20 18:00:36 Reply

"Wtf" you say? "All that for a stupid triangle!? Its not even in 3d!!" well yea. I never said it was easy. The reason I put up the source for a 2d triangle is because that is the only example I can find on my comp that doesn't need multiple .cpp files, .h files, and resource files in order to compile.
In all fairness though, its really not as tough as it looks. The first part of the code (the WinMain and WinProc fucntion) is for making the window. To make any sense out of it you're going to need to know windows programming (which is a whole other task in itself). But for right now you can just forget about it. The important part is right under the comment "// OpenGL animation code goes here". This is where the triangle is made and rotated. The last part of the code is just for initializing/uninitializing openGL. If you can memorize all this it will help you a great deal in learning openGL and directx because just about every game/3d application has this basic code in it somewhere. The key is to just play around with it and keep looking at it and eventually it will start to click. If you think you can handle more of it you can find a ton of good tutorial code at www.gametutorials.com. Good luck

Lordfat
Lordfat
  • Member since: May. 30, 2000
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to C++ Codes Here! 2005-02-20 18:14:27 Reply

Oh and I forgot to mention. If you can get your hands on a good version of the Directx SDK it has the source code for just about everything you need to make a modern 3d game. I got mine off a CD and its different from the one on the Microsoft website, so you might have to look around. But its got everything. From dymanic lighting, to bump mapping, to vertex shading... its all there.

0x41
0x41
  • Member since: Dec. 30, 2004
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to C++ Codes Here! 2005-02-20 18:19:54 Reply

At 2/4/05 11:02 PM, eh-productions wrote: can someone help me with colored text in c++. i need to make five different colors but i don't know how to do it. i need something like

colored text == green;
cout<<"this is green";

or something simple like that.

Compile as Win32 GUI/Win32 Application


#include <windows.h>

LRESULT CALLBACK WindProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX WndCls;
static char szAppName[] = "Colorthing";
MSG Msg;

WndCls.cbSize = sizeof(WndCls);
WndCls.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
WndCls.lpfnWndProc = WindProcedure;
WndCls.cbClsExtra = 0;
WndCls.cbWndExtra = 0;
WndCls.hInstance = hInstance;
WndCls.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndCls.hCursor = LoadCursor(NULL, IDC_CROSS);
WndCls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndCls.lpszMenuName = NULL;
WndCls.lpszClassName = szAppName;
WndCls.hIconSm = LoadIcon(hInstance, IDI_APPLICATION);
RegisterClassEx(&WndCls);

CreateWindowEx(WS_EX_OVERLAPPEDWINDOW,
szAppName,
"Color thing",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);

while( GetMessage(&Msg, NULL, 0, 0) )
{
TranslateMessage(&Msg);
DispatchMessage( &Msg);
}

return static_cast<int>(Msg.wParam);
}

LRESULT CALLBACK WindProcedure(HWND hWnd, UINT Msg,
WPARAM wParam, LPARAM lParam)
{
HDC hDC;
PAINTSTRUCT Ps;
COLORREF clrRed = RGB(255, 25, 5);
COLORREF clrBlue = RGB(12, 25, 255);
COLORREF clrGreen = RGB(12, 255, 0);
COLORREF clrBlack = RGB(0, 0, 0);
COLORREF clrPink = RGB(255, 0, 240);
switch(Msg)
{
case WM_DESTROY:
PostQuitMessage(WM_QUIT);
break;
case WM_PAINT:
hDC = BeginPaint(hWnd, &Ps);
SetTextColor(hDC, clrRed);
TextOut(hDC, 50, 40, "TextRed", 7); //dimensions/text/sizeoftext
SetTextColor(hDC, clrBlue);
TextOut(hDC, 50, 80, "TextBlue", 8);
SetTextColor(hDC, clrGreen);
TextOut(hDC, 50, 120, "TextGreen", 9);
SetTextColor(hDC, clrBlack);
TextOut(hDC, 50, 160, "TextBlack", 9);
SetTextColor(hDC, clrPink);
TextOut(hDC, 50, 200, "TextPink", 8);
EndPaint(hWnd, &Ps);
break;
default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
return 0;
}

Cinjection
Cinjection
  • Member since: Apr. 6, 2004
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to C++ Codes Here! 2005-02-20 20:14:45 Reply

ok well mabey its just my compiler but nither of those worked. lordfat i compiled yours and got 14 errors and 0x41's i got 1 error in a win 32 aplication. Mabey its just my compiler(VC++)

0x41
0x41
  • Member since: Dec. 30, 2004
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to C++ Codes Here! 2005-02-20 20:41:21 Reply

What error?

Cinjection
Cinjection
  • Member since: Apr. 6, 2004
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to C++ Codes Here! 2005-02-20 21:01:12 Reply

well for yours i got this error:
(22) : error C2447: missing function header (old-style formal list?)
and for the other guy i got like 14 that i won't mention

Lordfat
Lordfat
  • Member since: May. 30, 2000
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to C++ Codes Here! 2005-02-20 23:52:06 Reply

Alright well then try this: Download and install Dev-C++, go to tools->check for updates, and download everything with OpenGL in it. One of those will install to the folder DevC++/examples/OpenGL and it will be the same code I posted. Open the project file (.dev) and it should compile.

Cinjection
Cinjection
  • Member since: Apr. 6, 2004
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to C++ Codes Here! 2005-02-21 17:07:43 Reply

ah well its not worth the effort and time for a 2-d trinagle but i'll get it later. C++ really does own. I've been told somewhere that a tic-tak-toe prog in VB that i made could be reduced from 1,400 to 400. How would that work exactly? It was pretty good cuz it had single and mulitplayer mode along with a decent A.I. for single player.

magpieOfDoom
magpieOfDoom
  • Member since: Feb. 10, 2005
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to C++ Codes Here! 2005-02-21 18:12:10 Reply

At 2/21/05 05:07 PM, Love_Daddy wrote: ah well its not worth the effort and time for a 2-d trinagle but i'll get it later. C++ really does own. I've been told somewhere that a tic-tak-toe prog in VB that i made could be reduced from 1,400 to 400. How would that work exactly? It was pretty good cuz it had single and mulitplayer mode along with a decent A.I. for single player.

Tic Tac Toe (Src).
This is about 420 lines, but it contains a bunch of useless comments and the code is fairly neat.

thoughtpolice
thoughtpolice
  • Member since: Mar. 24, 2003
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to C++ Codes Here! 2005-02-21 18:27:59 Reply

At 2/21/05 05:07 PM, Love_Daddy wrote: C++ really does own.

Urg, I hate when people say that. Matter o' fact, I pretty much hate it when people say that with any language.

I'm not saying it isn't good or anything, I just mean, it's not the best language for everything you could ever encouter in your entire life of programming.


omg.
Playstation Network tag: muffin-noodle
the empty set

Cinjection
Cinjection
  • Member since: Apr. 6, 2004
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to C++ Codes Here! 2005-02-21 19:04:59 Reply

At 2/21/05 06:12 PM, misterPhyrePhox wrote:
Tic Tac Toe (Src).
This is about 420 lines, but it contains a bunch of useless comments and the code is fairly neat.

no no thats nice but i ment using a G.U.I. like having a pic for each move and what not. lol i'd post the code in the VB codes here thread i made but it would take liek 4 pages lol.

Ravens-Grin
Ravens-Grin
  • Member since: Jun. 3, 2003
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to C++ Codes Here! 2005-02-21 19:27:44 Reply

Here's something that will change text into ALL CAPS, and another function that will change it into no caps. I know there's probably a function in the library to do this, but I will explain the actual concept behind this. (Well actually it will only do one letter at a time, and it does not account for other ASCII characters like 1,2 ,3…. And ‘,’ ‘.’ and ‘\’)

As everyone knows here, computers run in binary, 0's and 1's. If you do a sizeof(char); you will realize that an ASCII character takes up only 1 byte, 8 bits, or 256 possible combinations of 0's and 1's(2^8).
Now for text like what you are seeing, it takes up about 42 characters, including all caps and lower case.
Let's examine the letter 'a' in binary and the letter 'A' in binary as well... but let's disect it using some code...

ok so how in the world are we going to get the binary value of 'a' and the binary value of 'A'? Well we could just look it up in an ASCII chart, but that would be a little too easy. What we could also do is to do a type of "conversion." C++ has an easy way to do a quickie conversion in which in a function you put in paranthesis around the type you want the variable to be real quick. Don't understand? Well look at the code below and try to understand.

#include <iostream>

int main()
{
char x='A';
char y='a'; /* ok, I could've just called these variables a and A because c++ is case sensitive, but oh well */
std::cout<<(int) x<< "/n"<< (int) y;
return 0;
};

Notice how I put paranthesis around the type that I wanted the variable to be? Try it without the paranthesis. It won't work. It's because your trying to redefine the variable, and not just view it as a type integer.

You should get 65 decimal for the lowercase a and 97 decimal for the uppercase A. Just to make this shorter, I'll just convert this to binary. (If people really want me to explain, I will)

A= 01000001
a= 01100001

As you can see, only 1 "1" changed the value of a lowercase a to an uppercase A. You can do this for the entire spectrum of values, but let me just say the first 3 letters of the binary values will stay the same throughout the alphabet, with z being 01011010 and Z being 01111010. So now how do we change it to all caps or to no caps at all? Easy, just figure out a way to change that little 3rd bit in the values.

So now we have to manipulate the values of the binary code. Once again c++ gives us the power to do this. We have the AND function, the OR function, and the XOR function. Let me give an example of each(remember this is in binary, in which 1 is true and 0 is false)....
AND--- 0 & 1 = 0 1 & 1 = 1 1 & 0 = 0
OR-- 1 | 0 = 1 1 | 1 = 1 0 | 1= 0
Exclusive or (XOR) 1 ^ 0 = 1 1 ^ 1 = 0 0 ^ 1= 1

^, &, and | (which is below the backspace on the keyboard and it looks like two vertical lines) are like +, *, / signs in math. They all resemble an operation. (God I hope this isn't too long....)

So if we OR a char and a char type, it would do similar operation bit by bit.
01100001 ( which is lowercase a, or 97 in decimal)
OR 00100000 (223 in decimal)
01000001 ( which is uppercase A, or 65 in decimal)

So that's how we switch from lower case to uppercase. We use the XOR to get lowercase....
01000001
XOR 00100000 (which is 32 in decimal)
01100001

So finally now in C++ (only does one char at a time, so needs to be rewritten to do an entire string.....)

#include <iostream>
using namespace std;

char to_lower(char x);
char to_upper(char x);

int main()
{
char y;
while(1)
{
cin>>y;
cout<< to_lower(y) << "\n" << to_upper(y) << "\n";
}
return 0;
};

char to_lower(char x) /* NOTE: when doing functions, it only passes a value, so it's perfectly legal to do what I just did*/
{
int lower_constant= 32; // the decimal value of 11011111
return (x | ((char) lower_constant)); //eh, I'm lazy. it's going to pass this value back anyways so I don't need to store it in a variable, also | is the operator for or.
};

char to_upper(char x)
{
int upper_constant= 32;
return ( x ^ ((char) upper_constant)); // ^ is the operator for XOR, and not for power stuff, so with that, this would not be valid 2^3=8. That is not true in this case.
};

Comments, questions, concerns???

Cinjection
Cinjection
  • Member since: Apr. 6, 2004
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to C++ Codes Here! 2005-02-21 19:35:07 Reply

not bad dude thanx for the info!

Ravens-Grin
Ravens-Grin
  • Member since: Jun. 3, 2003
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to C++ Codes Here! 2005-02-21 19:55:15 Reply

At 2/21/05 07:35 PM, Love_Daddy wrote: not bad dude thanx for the info!

thanks... oh by the way I just thought of a quick and easy way to make sure you don't and a character like a period, semicolon, or what not... and I found a horrendous typo in which I should've caught, which affects the to_upperr function.

the changes are to the to_lower and the to_upper functions...(adding spaces for clarity)


char to_lower(char x) /* NOTE: when doing functions, it only passes a value, so it's perfectly legal to do what I just did*/
{
int lower_constant= 32; // the decimal value of 11011111
if( ( ((int) x >= 65) && (((int) x) <= 90) ) || ( ((int) x >= 97) && ( (int) x <= 122)))
{
return (x | ((char) lower_constant)); }
else{

return x;
}
//eh, I'm lazy. it's going to pass this value back anyways so I don't need to store it in a variable, also | is the operator for or.
};

char to_upper(char x)
{
int upper_constant= 223;
if( ( ((int) x >= 65) && ((int) x <= 90) ) || ( ((int) x >= 97) && ( (int) x <= 122)))
{ return ( x & ((char) upper_constant)); } // ^ is the operator for XOR, and not for power stuff, so with that, this would not be valid 2^3=8. That is not true in this case.
else
{
return x;
}
};

Cinjection
Cinjection
  • Member since: Apr. 6, 2004
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to C++ Codes Here! 2005-02-21 20:02:01 Reply

while your typing in code u feel like typing in a number sorter and explaining it. I made one and posted it a while back and i don't knwo if its the most efficient(i know its not). If you want to see it its on one of the last couple of pages.

magpieOfDoom
magpieOfDoom
  • Member since: Feb. 10, 2005
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to C++ Codes Here! 2005-02-21 20:22:30 Reply

At 2/21/05 08:02 PM, Love_Daddy wrote: while your typing in code u feel like typing in a number sorter and explaining it. I made one and posted it a while back and i don't knwo if its the most efficient(i know its not). If you want to see it its on one of the last couple of pages.

The best, easiest way would be to use STL (Note: This was written in BBS, so it might be buggy):

#include <stdio.h>
#include <vector>
#include <algorithm>
#include <utility>

void main() {
vector<int> vNumbers; // A vector is a list-like storage structure. The <int> just denotes that it holds integer values.
int iBuffer; // Just a buffer for reading in values.
while(true) {
scanf("%i", &iBuffer);
if(iBuffer == 0) break;
vNumbers.push_back(iBuffer); // Push back just inserts the buffer into the back of the list.
}
sort(vNumbers.begin(), vNumbers.end(), greater<int>); // This is pretty self explanatory. It sorts from the beginning of the list to the end of the list using greater<int>(), which is a function that returns a boolean and determines whether the value should be swapped or not.
// Iterators allow you to access and iterate through the contents of the list. You could also use the [] operator, but iterators are faster. Its a lot like for(int i = 0; i < size; i++) { ... }
for(vector<int>::iterator i = vNumbers.begin(); i != vNumbers.end(); ++i) printf("%i\n", (*i));
}

magpieOfDoom
magpieOfDoom
  • Member since: Feb. 10, 2005
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to C++ Codes Here! 2005-02-21 20:25:42 Reply

Grr... add using namespace std; after the includes. Why doesnt NG have an edit button?

Cinjection
Cinjection
  • Member since: Apr. 6, 2004
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to C++ Codes Here! 2005-02-21 21:36:51 Reply

At 2/21/05 08:25 PM, misterPhyrePhox wrote: Grr... add using namespace std; after the includes. Why doesnt NG have an edit button?

it'd be a lot cooler if the did. i never used "using namespace std;" because i never knew what it did so blah.

Kaabi
Kaabi
  • Member since: Jul. 6, 2003
  • Offline.
Forum Stats
Member
Level 23
Blank Slate
Response to C++ Codes Here! 2005-02-21 22:19:24 Reply

Damn I really need to start learning C++ again. I'd be a modifier yes I'd be.

Peaceblossom
Peaceblossom
  • Member since: Dec. 23, 2003
  • Offline.
Forum Stats
Member
Level 25
Reader
Response to C++ Codes Here! 2005-02-21 22:49:24 Reply

At 2/21/05 09:36 PM, Love_Daddy wrote:
At 2/21/05 08:25 PM, misterPhyrePhox wrote: Grr... add using namespace std; after the includes. Why doesnt NG have an edit button?
it'd be a lot cooler if the did. i never used "using namespace std;" because i never knew what it did so blah.

really?
i think it just makes it so you don't have to type " std::cout<<"blah";
it makes it so that all the keywords like cout, cin, and various others maybe say std::cout when you type cout


BBS Signature
Ravens-Grin
Ravens-Grin
  • Member since: Jun. 3, 2003
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to C++ Codes Here! 2005-02-21 23:05:09 Reply

At 2/12/05 12:04 AM, eh-productions wrote:

:...: goto begg;

}else{
if(guess == guesser){
cout<<"Correct, Would you like to play again? Press 1 for yes and 2 for no"<<endl;
cin>>yesno;
if(yesno == 1){
goto rewind;
}else{
return 0;
}
}
}
}
}
}

hey eh, generally do not use goto statements in C++. Try rewriting that using either a while statement or a for statement

Kaabi
Kaabi
  • Member since: Jul. 6, 2003
  • Offline.
Forum Stats
Member
Level 23
Blank Slate
Response to C++ Codes Here! 2005-02-22 09:22:01 Reply

I heard goto statements in programming are horrible to use. I'm not sure why, I think its just cause it makes the program jump around and its hard to read the code if its long with the goto so gotos are bad.

magpieOfDoom
magpieOfDoom
  • Member since: Feb. 10, 2005
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to C++ Codes Here! 2005-02-22 14:27:42 Reply

"Spaghetti Code"
I'm not sure why they even include goto statements in C++ -- no one really uses them in large programs because the obfuscate the code to the point of mind-bogglingness.

Cinjection
Cinjection
  • Member since: Apr. 6, 2004
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to C++ Codes Here! 2005-02-22 15:27:59 Reply

well heres soem code

#include <iostream.h>

int main(){

int counter = 1;

while(counter = 1){
cout<<"Happy birthday to Love_Daddy"
}
return 0;
}

Ravens-Grin
Ravens-Grin
  • Member since: Jun. 3, 2003
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to C++ Codes Here! 2005-02-22 18:02:46 Reply

Can someone give me a kinda complex project (besides a game engine) so that I can get my C++ skills back up to speed?

DumbGenius
DumbGenius
  • Member since: Feb. 21, 2005
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to C++ Codes Here! 2005-02-22 19:04:40 Reply

//prog input file to output array

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
ifstream infile;
string inname;
int array[3];
int n=0;
char i;

cout<<"Enter input file name"<<endl;
cin>>inname;

infile.open(inname.c_str());

if (infile.fail())
cout<<"error"<<endl;

else
{
cout<<"Enter input file"<<endl;
cin>>inname;
}

while (!infile.eof())
{
infile>>i;
array[n]=i;
}

infile.close();
}

Peaceblossom
Peaceblossom
  • Member since: Dec. 23, 2003
  • Offline.
Forum Stats
Member
Level 25
Reader
Response to C++ Codes Here! 2005-02-22 19:04:50 Reply

thanks guys for the 'speghetti code' update although i already realized this a while ago. could somebody maybe help me re-write it with a while loop or something like that. also, i am in desperate need of a project to work on. can someone pitch a few ideas for a simple yet usefull programming idea? i wanna make a game but i'm not particualirly fond of making a simple number guesser or anything like that.

well if anyone can help with either of these to things that would be a real help. thanks!


BBS Signature
DumbGenius
DumbGenius
  • Member since: Feb. 21, 2005
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to C++ Codes Here! 2005-02-22 19:08:09 Reply

//loop

#include <iostream>

using namespace std;

int main()
{
char j;
j='c';

while (j=='c')
{
for (int i=0; i<100; i++)
{
cout<<i<<" ";
}
cout<<endl<<"To continue press 'c' and 'Enter' on the keyboard. Press anything else to exit.\n";
cin>>j;
}

return 0;
}

magpieOfDoom
magpieOfDoom
  • Member since: Feb. 10, 2005
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to C++ Codes Here! 2005-02-22 19:18:29 Reply

@eh-productions: Have you written a Tic Tac Toe AI yet? Or a checkers AI?