Author Topic: [C/C++] Joe vs Ergot: Code wars!  (Read 19809 times)

0 Members and 1 Guest are viewing this topic.

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
[C/C++] Joe vs Ergot: Code wars!
« on: September 27, 2005, 07:26:53 pm »
Yeah, me and Ergot are having a little friendly competition on outcoding eachothers projects. We're both novices to C++, so we're pretty equal. Right now, we've both finished exponents in our calculator projects. Anyhow, I submit the next project in my side of the war, the ..dun dun dun.. BINARY CONVERTER!

joe@JoeMomma:~/dev/cpp/helloworld $ g++ -Wno-deprecated binconv.cpp -o binconv && ./binconv
Enter binary digits:
1
0
0
0
0
0
0
1
10000001b = 129


EDIT -
If anyone is interested in learning C++, but doesn't have very much knoledge of the language, feel free to write some small projects. I don't know about the rest of you, but being in a competitive environment (like this) sort of drives me to outpreform the others, and in this case learn C++ faster. So yeah, join up if you feel like it. And Newby, before you write an ubercool Battle.net bot and say you win: don't. =p
« Last Edit: September 27, 2005, 11:05:54 pm by Joe[e2] »
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: [C++] Joe vs Ergot: Code wars!
« Reply #1 on: September 27, 2005, 07:41:51 pm »
I think Ergot will win.
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [C++] Joe vs Ergot: Code wars!
« Reply #2 on: September 27, 2005, 08:40:15 pm »
Thanks. He hasn't written a binary converter yet, so eh? I'm ahead unless he has another project up his sleves.
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Ergot

  • 吴立峰 ^_^ !
  • x86
  • Hero Member
  • *****
  • Posts: 3724
  • I steal bandwidth. p_o
    • View Profile
Re: [C++] Joe vs Ergot: Code wars!
« Reply #3 on: September 27, 2005, 08:47:36 pm »
No... First I do everything in C. Second, my main goal is just to take your code and make it better ^_~
Mynd, I wouldn't bet on myself... my attempt at learning VB was something that should be shot, burned, buried, and then nuked ten times.
You can ask Joe how poor one of my projects turned out ;P
« Last Edit: September 27, 2005, 08:49:30 pm by Ergot »
Who gives a damn? I fuck sheep all the time.
And yes, male both ends.  There are a couple lesbians that need a two-ended dildo...My router just refuses to wear a strap-on.
(05:55:03) JoE ThE oDD: omfg good job i got a boner thinkin bout them chinese bitches
(17:54:15) Sidoh: I love cosmetology

Offline Eric

  • Full Member
  • ***
  • Posts: 304
  • I'm new here!
    • View Profile
Re: [C++] Joe vs Ergot: Code wars!
« Reply #4 on: September 27, 2005, 09:19:53 pm »
If Ergot even contemplates coding correctly, he'll have you beaten by a long shot in every language you've ever programmed in, Joe.

Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: [C++] Joe vs Ergot: Code wars!
« Reply #5 on: September 27, 2005, 09:25:52 pm »
Out of curiosity Joe, when does your converter know to stop taking input?
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline Ergot

  • 吴立峰 ^_^ !
  • x86
  • Hero Member
  • *****
  • Posts: 3724
  • I steal bandwidth. p_o
    • View Profile
Re: [C++] Joe vs Ergot: Code wars!
« Reply #6 on: September 27, 2005, 09:44:53 pm »
Wow you guys must really hate Joe, because honestly... he was much better at VB than I will ever be at it ;P
Who gives a damn? I fuck sheep all the time.
And yes, male both ends.  There are a couple lesbians that need a two-ended dildo...My router just refuses to wear a strap-on.
(05:55:03) JoE ThE oDD: omfg good job i got a boner thinkin bout them chinese bitches
(17:54:15) Sidoh: I love cosmetology

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: [C++] Joe vs Ergot: Code wars!
« Reply #7 on: September 27, 2005, 09:51:41 pm »
Out of curiosity Joe, when does your converter know to stop taking input?
Looks like he limited it to 8 bytes.

Offline Ergot

  • 吴立峰 ^_^ !
  • x86
  • Hero Member
  • *****
  • Posts: 3724
  • I steal bandwidth. p_o
    • View Profile
Re: [C++] Joe vs Ergot: Code wars!
« Reply #8 on: September 27, 2005, 10:16:22 pm »
I'm guessing he just used cin 8 times.
Who gives a damn? I fuck sheep all the time.
And yes, male both ends.  There are a couple lesbians that need a two-ended dildo...My router just refuses to wear a strap-on.
(05:55:03) JoE ThE oDD: omfg good job i got a boner thinkin bout them chinese bitches
(17:54:15) Sidoh: I love cosmetology

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [C++] Joe vs Ergot: Code wars!
« Reply #9 on: September 27, 2005, 10:53:11 pm »
Yeah, I defined a b c d e f g and h as integers and cin'd them. Its a sloppy++ way of doing it, but it works.

After that, I go through them backwards, perform an if statment on them (if = 1) and increase int accum accordingly, then I print them it to the screen.


I optimized the living daylights out of it, and its now about twice as short.

joe@JoeMomma:~/dev/cpp/helloworld $ g++ -Wno-deprecated binconv.cpp -o binconv && ./binconv
Enter binary digits:
1
1
1
1
1
1
1
1
Result: 255


// C++ binary converter
// Author: Joe[e2]
//
// TODO:
// Input the binary values as a string instead of integers, so that it can be done on one line.

#include <iostream.h>
#include <stdio.h>

int main() {
  int i;
  int accum = 0;

  printf("Enter binary digits:\n");
  cin >> i; if(i = 1) { accum = accum + 128; }
  cin >> i; if(i = 1) { accum = accum +  64; }
  cin >> i; if(i = 1) { accum = accum +  32; }
  cin >> i; if(i = 1) { accum = accum +  16; }
  cin >> i; if(i = 1) { accum = accum +   8; }
  cin >> i; if(i = 1) { accum = accum +   4; }
  cin >> i; if(i = 1) { accum = accum +   2; }
  cin >> i; if(i = 1) { accum = accum +   1; }

  cout << "Result: " << accum << "\n";
  return 0;
}


EDIT -
Oops I did it again!
joe@JoeMomma:~/dev/cpp/helloworld $ g++ -Wno-deprecated binconv2.cpp -o binconv2 && ./binconv2
Enter binary digits:
10010010
10010010b = 146
joe@JoeMomma:~/dev/cpp/helloworld $ g++ -Wno-deprecated binconv2.cpp -o binconv2 && ./binconv2
Enter binary digits:
11111111
11111111b = 255


// C++ binary converter
// Author: Joe[e2]

#include <iostream.h>
#include <stdio.h>

int main() {
  char binary[8];
  int accum = 0;
  int add = 128;

  printf("Enter binary digits:\n");
  cin >> binary;
  for(int i = 0; i < 8; i++) {
    if(binary == 0x31) { accum = accum + add; }
    add = add / 2;
  }

  cout << binary << "b = " << accum << "\n";
  return 0;
}


EDIT -
Hm, in the first code I posted, I suppose it would always return 255, due to the fact I'm testing if 1 can be asigned to i, instead of if i == 1. Oh well, its fixed in the second one.
« Last Edit: September 27, 2005, 11:29:11 pm by Joe[e2] »
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #10 on: September 27, 2005, 11:50:24 pm »
Now, a decimal->binary converter! Yay!

joe@JoeMomma:~/dev/cpp/helloworld $ g++ -Wno-deprecated binconv-rev.cpp -o binconv-rev && ./binconv-rev
Enter decimal number:
99
99 = 01100011¼ùÿ¿¶÷@b
joe@JoeMomma:~/dev/cpp/helloworld $ g++ -Wno-deprecated binconv.cpp -o binconv && ./binconv
Enter binary digits:
01100011
01100011b = 99


// C++ decimal->binary converter
// Author: Joe[e2]

#include <iostream.h>
#include <stdio.h>

int main() {
  char binary[8];
  int input;
  int accum = 0;
  int sub = 128;

  printf("Enter decimal number:\n");
  cin >> input; accum = input;
  for(int i = 0; i < 8; i++) {
    if(accum >= sub) {
      accum = accum - sub;
      binary = 0x31;
    }else{
      binary = 0x30;
    }
    sub = sub / 2;
  }

  cout << input << " = " << binary << "b\n";
  return 0;
}
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Ergot

  • 吴立峰 ^_^ !
  • x86
  • Hero Member
  • *****
  • Posts: 3724
  • I steal bandwidth. p_o
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #11 on: September 28, 2005, 12:36:13 am »
Ahh I never thought of it like that (dividing by two :()... I gave this like half an hours worth of thought... then I had to fix the sink :(
There was bugs I wanted work out (Like making sure numbers other than 0's and 1's wouldn't mess up the program) but meh... I'll do it later... maybe.
Proof that Joe > Me ;D
My crappy code:
Code: [Select]
#include <stdio.h>

int a;

int bintodec(a)
{
        int dec;
        dec = 0;
        while (a != 0)
        {
                if (a > 11111111)
                        {
                        a = a - a;
                        dec = 256;
                        }
                else if (a >= 10000000)
                        {
                        dec = dec + 128;
                        a = a - 10000000;
                        }
                else if (a >= 1000000)
                        {
                        dec = dec + 64;
                        a = a - 1000000;
                        }
                else if (a >= 100000)
                        {
                        dec = dec + 32;
                        a = a - 100000;
                        }
                else if (a >= 10000)
                        {
                        dec = dec + 16;
                        a = a - 10000;
                        }
                else if (a >= 1000)
                        {
                        dec = dec + 8;
                        a = a - 1000;
                        }
                else if (a >= 100)
                        {
                        dec = dec + 4;
                        a = a -100;
                        }
                else if (a >= 10)
                        {
                        dec = dec + 2;
                        a = a - 10;
                        }
                else if (a >= 1)
                        {
                        dec = dec + 1;
                        a = a - 1;
                        }
                }
        return dec;
}

int main()
{
        int bin, result;
        printf("Enter an 8-bit binary number: \n");
        scanf("%d",&bin);
        result = bintodec(bin);
        if (result >= 256)
                printf("8 bit binary numbers only.\n");
        else
        printf("%d in decimal is %d.\n",bin, result);
        return 0;
}

« Last Edit: September 28, 2005, 12:42:22 am by Ergot »
Who gives a damn? I fuck sheep all the time.
And yes, male both ends.  There are a couple lesbians that need a two-ended dildo...My router just refuses to wear a strap-on.
(05:55:03) JoE ThE oDD: omfg good job i got a boner thinkin bout them chinese bitches
(17:54:15) Sidoh: I love cosmetology

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #12 on: September 28, 2005, 07:41:30 am »
You're going to want to check if(num >= 2) instead, because your method can return false negatives.

EDIT -
Proof of concept, anything except the first bit is a 2. =p

Anyhow, my shellscript skills rock.

joe@JoeMomma:~/dev/cpp/helloworld $ ./build && ls bin
Building files..
binconv.cpp
binconv-rev.cpp
Math.cpp
DivTable.cpp
functest.cpp
MultTable.cpp
MultTable2.cpp
Finished!
binconv  binconv-rev  DivTable  functest  Math  MultTable  MultTable2


echo Building files..
echo binconv.cpp
g++ -Wno-deprecated binconv.cpp -o bin/binconv
echo binconv-rev.cpp
g++ -Wno-deprecated binconv-rev.cpp -o bin/binconv-rev
echo Math.cpp
g++ -Wno-deprecated Math.cpp -o bin/Math
echo DivTable.cpp
g++ -Wno-deprecated DivTable.cpp -o bin/DivTable
echo functest.cpp
g++ -Wno-deprecated functest.cpp -o bin/functest
echo MultTable.cpp
g++ -Wno-deprecated MultTable.cpp -o bin/MultTable
echo MultTable2.cpp
g++ -Wno-deprecated MultTable2.cpp -o bin/MultTable2
echo Finished!

# -rw-r--r--    1 joe      joe           379 2005-09-27 23:01 binconv.cpp
# -rw-r--r--    1 joe      joe           471 2005-09-28 06:59 binconv-rev.cpp
# -rw-r--r--    1 joe      joe           912 2005-09-26 18:54 calculator.cpp
# -rw-r--r--    1 joe      joe           585 2005-09-25 21:31 DivTable.cpp
# -rw-r--r--    1 joe      joe           226 2005-09-27 22:16 functest.cpp
# -rw-r--r--    1 joe      joe           226 2005-09-24 18:50 Math.cpp
# -rw-r--r--    1 joe      joe           584 2005-09-25 00:38 MultTable2.cpp
# -rw-r--r--    1 joe      joe           698 2005-09-24 20:51 MultTable.cpp
« Last Edit: September 28, 2005, 07:59:19 am by Joe[e2] »
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #13 on: September 28, 2005, 12:43:16 pm »
This was my solution:
Code: [Select]
#include <iostream>

int main(void);
typedef unsigned long int DWORD;
typedef unsigned char BYTE;
using namespace std;

int main()
{
    DWORD numBits, curBit, inBit;
    DWORD val;
char empty;
    numBits = 0;
    curBit = 0;
    val = 0;
    do
    {
         cout << "Enter the number of bits (1 to 32) that you will be entering, from MSB to LSB." << endl;
         cin >> numBits;
    } while (numBits < 1 || numBits > 32);

    cout << "Accepting " << numBits << " bits:" << endl;
    for (curBit = numBits; curBit > 0; curBit--)
    {
        inBit = 2;

        while (inBit > 1)
        {
            cin >> inBit;

            if (inBit < 2)
break;
            cout << "Error: invalid bit (specify 0 or 1)." << endl;
        }

        if (inBit)
            val |= (inBit << (curBit - 1));
    }

    cout << "You entered: " << val << "." << endl;

cin >> empty;

return 0;
}

Enter the number of bits (1 to 32) that you will be entering, from MSB to LSB.
20
Accepting 20 bits:
0
1
1
0
0
1
1
1
1
0
0
0
1
0
1
1
0
1
0
0
You entered: 424116.


This was the decimal to binary converter:
Code: [Select]
#include <iostream>

int main(void);
typedef unsigned long int DWORD;
using namespace std;

int main()
{
    DWORD val;
char empty;
int i;
cout << "Enter a value from 0 to 4294967295:" << endl;
cin >> val;

cout << "You entered (in binary): ";
for (i = 31; i >= 0; i--)
{
if (val & (1 << i))
cout << "1";
else
cout << "0";

if (i % 8 == 0)
cout << " ";
}
cout << "b" << endl;

cin >> empty;
}

Enter a value from 0 to 4294967295:
884376993
You entered (in binary): 00110100 10110110 10000101 10100001 b


Both compile with Visual C++ 2003.

Joe, some comments (Ergot....  you need more help than comments ;)):

1.) Don't #include <iostream.h>, #include <iostream>.  That's standard C++.
2.) Why are you using ASCII literals (0x30, 0x31) as characters?  '0' and '1' work fine.
3.) Why are you using printf() in a C++ program?  Use cout.  (Unless you're formatting strings).
4.) accum = accum - sub; == accum -= sub;
5.) You shouldn't put programming statements on the same line as I/O (IMO), for example: cin >> accum; if (accum) dosomething(); -- I think that's ugly.
6.) You should have come up with a better way to do what you did in the first program.  What if your project manager wanted you to convert 32-bit numbers?  Can you imagine typing out all those literals?  Or even macros? [edit]Hrm, your third go was better, but you still could have done better with it.  Why not just cin to an int and test for 1 or 0?  (Note that my program tested for illegal values also -- what would yours do if I put in a 2 or something?)[/edit]

And DON'T make the standard I'm-Joe-I'm-Lazy argument.  Part of what likely discourages you from completing your projects is that you get frustrated when you have to go back and correct things.  Be un-lazy and do it right the first time and you don't need to spend time being consistent (like upgrading your code to take a 32-bit number).

Ergot, I wasn't trying to pick on you.  It seems like you just need to experience better what the computer is capable of doing, because it looks like you're taking the long way to get where you're going, but only because you don't know any better.
« Last Edit: September 28, 2005, 01:04:21 pm by MyndFyre[x86] »
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #14 on: September 28, 2005, 03:43:31 pm »
2.) Why are you using ASCII literals (0x30, 0x31) as characters?  '0' and '1' work fine.

Yes, for God sakes, anybody who does that should be shot dead. 

When I mark assignments, I see people do it all the time.  I'm not really sure whether they think they're being clever, or if they're just as dumb as a post.  Either way, it's a terribly annoying thing to do for _anybody_ reading the code.  Even somebody like me who knows the common ascii code will be slowed down. 

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #15 on: September 28, 2005, 05:21:18 pm »
Quote
1.) Don't #include <iostream.h>, #include <iostream>.  That's standard C++.
mmk. I think that should fix the need for -Wno-deprecated too.

Quote
2.) Why are you using ASCII literals (0x30, 0x31) as characters?  '0' and '1' work fine.
Oops, my attempt to do that was with double quotes.

Quote
3.) Why are you using printf() in a C++ program?  Use cout.  (Unless you're formatting strings).
Uh, hehe. *fix*

Quote
4.) accum = accum - sub; == accum -= sub;
Yeah, I was having trouble with that. I'll check it out again.

Quote
5.) You shouldn't put programming statements on the same line as I/O (IMO), for example: cin >> accum; if (accum) dosomething(); -- I think that's ugly.
I tend not to, but its much easier to follow in that particular instance, and looks cleaner. But usually, yeah, its ugly.

Quote
6.) You should have come up with a better way to do what you did in the first program.  What if your project manager wanted you to convert 32-bit numbers?  Can you imagine typing out all those literals?  Or even macros? [edit]Hrm, your third go was better, but you still could have done better with it.  Why not just cin to an int and test for 1 or 0?  (Note that my program tested for illegal values also -- what would yours do if I put in a 2 or something?)[/edit]
If I had to convert a 32-bit number, I'd edit my program to allow that. If I had intended this to be distributed (in which case I should be shot =p), I would allow that, though. If you put a 2 in my program, 2!=1 so it would mistake it for a 0.
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #16 on: September 28, 2005, 05:46:14 pm »
Quote
6.) You should have come up with a better way to do what you did in the first program.  What if your project manager wanted you to convert 32-bit numbers?  Can you imagine typing out all those literals?  Or even macros? [edit]Hrm, your third go was better, but you still could have done better with it.  Why not just cin to an int and test for 1 or 0?  (Note that my program tested for illegal values also -- what would yours do if I put in a 2 or something?)[/edit]
If I had to convert a 32-bit number, I'd edit my program to allow that. If I had intended this to be distributed (in which case I should be shot =p), I would allow that, though. If you put a 2 in my program, 2!=1 so it would mistake it for a 0.
My point was this:
Code: [Select]
  cin >> i; if(i = 1) { accum = accum + 128; }
  cin >> i; if(i = 1) { accum = accum +  64; }
  cin >> i; if(i = 1) { accum = accum +  32; }
  cin >> i; if(i = 1) { accum = accum +  16; }
  cin >> i; if(i = 1) { accum = accum +   8; }
  cin >> i; if(i = 1) { accum = accum +   4; }
  cin >> i; if(i = 1) { accum = accum +   2; }
  cin >> i; if(i = 1) { accum = accum +   1; }
If you were going to do it that way, then you'd need to go back and enter the literals for every case in a 32-bit (or arbitrary-length) number.

My point was that, you should look for a better algorithm to do something like this the first time (before you code x += literals 8 times) so that you didn't have to go back to fix it.

An alternative way doing something a LOT closer to what you were doing:

Code: [Select]
inline void accumTest(int &accum, int input, int pass)
{
  if (i == 1)
    accum |= (1 << pass);
}
// then where that series of code is:
// (that's the cin >> i; if (i == 1) accum = accum + literal;)
for (int n = 7; n <= 0; n++)
{
  cin >> i;
  accumTest(&accum, i, n);
}
That's called "refactoring," or splitting up function blocks so that operations are repeated less-frequently within code blocks.

Code cleanliness: increased.  Code writing: decreased overall.
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline Ergot

  • 吴立峰 ^_^ !
  • x86
  • Hero Member
  • *****
  • Posts: 3724
  • I steal bandwidth. p_o
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #17 on: September 28, 2005, 06:12:30 pm »
Mynd didn't I tell you I was a horrible programmer ;D ?
Who gives a damn? I fuck sheep all the time.
And yes, male both ends.  There are a couple lesbians that need a two-ended dildo...My router just refuses to wear a strap-on.
(05:55:03) JoE ThE oDD: omfg good job i got a boner thinkin bout them chinese bitches
(17:54:15) Sidoh: I love cosmetology

Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #18 on: September 28, 2005, 06:49:46 pm »
Mynd didn't I tell you I was a horrible programmer ;D ?

Ignorance can be cured by education, but the only cure for stupidity is death.

I believe you're in the former case.  ;)
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #19 on: September 28, 2005, 07:02:04 pm »
MyndFyre, not this last post, but the one just before Ergots, your sig got decapitated by Gecko. No clue what did it, but I can't see much more than the very top of your image on up.

Quote
(17:29:03) [x86] Ergot: You win ;D
(17:29:11) [x86] Ergot: Roofleskates

afk church
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Ergot

  • 吴立峰 ^_^ !
  • x86
  • Hero Member
  • *****
  • Posts: 3724
  • I steal bandwidth. p_o
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #20 on: September 28, 2005, 09:11:54 pm »
Ooo... This summerizes my coding:
Quote
On the subject of C program indentation:

        "In My Egotistical Opinion, most people's C programs should be indented six feet downward and covered with dirt."
                -- Blair P. Houghton
Who gives a damn? I fuck sheep all the time.
And yes, male both ends.  There are a couple lesbians that need a two-ended dildo...My router just refuses to wear a strap-on.
(05:55:03) JoE ThE oDD: omfg good job i got a boner thinkin bout them chinese bitches
(17:54:15) Sidoh: I love cosmetology

Offline AntiVirus

  • Legendary
  • x86
  • Hero Member
  • *****
  • Posts: 2521
  • Best
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #21 on: September 29, 2005, 12:32:55 pm »
Code: [Select]
/********************************************************/
/*                    Binary converter                  */
/*                     By Matt Fowler                   */
/*                philosopher150@yahoo.com              */
/*  converts text into binary using the division method */
/*                   through ASCII code                 */
/*compiled with the Dev-C++ compiler (www.bloodshed.net)*/
/********************************************************/

#include <iostream>
using namespace std;
#include <cstring>
#include <cstdlib>

char *entry, letter, choice[2];
int ascii, len, binary[8], total;
void prog();

int main()
{
      prog();     
      return 0;
}       
       
void prog()
{
   entry = new char[501];
   /* entry should be dynamic, otherwise a new
      string entry of 501 chars would be created
      each time function is called! 
      Talk about memory hog! */
   cout<<"Enter string to convert (up to 500 chars): ";
   cin.getline(entry, 500);
   len = strlen(entry);  /* get the number of characters in entry. */
   /* this loop is executed for each letter in the string. */
   for(int i = 0; i<len; i++)
   {
      total = 0;
      letter = entry[i]; /* store the first letter */
      ascii = letter;    /* put that letter into an int, so we can
                            see its ASCII number */
      while(ascii>0) /* This while loop converts the ASCII # into binary,
                        stores it backwards into the binary array. */
      {
         /* To get the binary code one must take the decimal number in
            question, take it and divide it by two repeatedly, save
            the remainder (which will become the binary number), save
            the whole number, divide by two, and repeat the whole
            process until 0 is reached.  This if-else statement serves
            this functionality, by getting the remainder of the ascii
            code, storing it in the array and then dividing the int
            ascii by two */
         if((ascii%2)==0)
         {
            binary[total] = 0;
            ascii = ascii/2;
            total++; /* increasing by one each time will yeild the
                        number of numbers in the array. */
         }
         else
         {
            binary[total] = 1;
            ascii = ascii/2;
            total++;
         }
      }
      total--; /* due to data type factors, the program will actually
                  add a 0 at the end of the array that is not supposed
                  to be there, decrementing total will solve this
                  problem, as that 0 will not be displayed. */
      /* this while loop displays the binary code for that letter. */
      while(total>=0)
      {
         cout<<binary[total];
         total--;
      }
   }
   delete[] entry; /* free up the memory used by entry */
   cout<<endl<<"Do again(1 = yes, 2= no)?: ";
   cin.getline(choice,3);
   if(choice[0] == '1')
      prog(); /* program is recursive, it calls itself.  It's kinda
                 like a function loop of sorts. */
   else
      exit(0); /* quits the program */ 
}
I found that at www.cplusplus.com 

Link: http://www.cplusplus.com/src/#vcpp

I played with it for awhile, it was fun. :)  But, it may help what you are doing, or give you ideas. 
The once grove of splendor,
Aforetime crowned by lilac and lily,
Lay now forevermore slender;
And all winds that liven
Silhouette a lone existence;
A leafless oak grasping at eternity.


"They say that I must learn to kill before I can feel safe, but I rather kill myself then turn into their slave."
- The Rasmus

Offline rabbit

  • x86
  • Hero Member
  • *****
  • Posts: 8092
  • I speak for the entire clan (except Joe)
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #22 on: September 29, 2005, 07:08:06 pm »
Code: [Select]
#include <stdio.h>

int main()
{
char *str = new char[256];
int val, pow = 1, pos = 0;

printf("input binary string followed by a \".\": ");
while(((val = getch()) != '.') || pos >= 255)
str[++pos] = val;

val = 0;

for(int i = 0; i < pos; i++)
{
if(str[i] == '.')
break;

if(str[i] == '1')
val += pow;

pow = (pow == 1) ? 2 : pow * pow;
}

printf("%ld", val);
}

Completely untested, but should work......

Offline dynobird

  • Newbie
  • *
  • Posts: 26
  • I'm new here!
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #23 on: October 01, 2005, 06:30:45 pm »
Here's my solution in Java :P (sorry, don't have a good c++ compiler atm, and can't install w/o dad being home.. I have no privileges... )
It's sorta long but it has good explanations.
And it doesn't let anyone flip my program out =p
Code: [Select]
/*
 * Main.java
 * Created on October 1, 2005, 6:17 PM
 * @author Andy
 */

/*
 * Binary -> Base10 Converter
 */

package binconv;

public class Main {
   
    static char[] binary;
    static String binaryStr;
   
    public static boolean isBinary() {
        for (int i = 0; i < binary.length; i++) {
            if (binary[i] != '1' && binary[i] != '0')
                return false;
        }
        return true;
    }
   
    public static void main(String[] args) {
        final int AGAIN = 1;
        final int END = 2;
        int decision;
        EasyReader in = new EasyReader(); // EasyReader and EasyWriter == best IO classes in Java!!
        System.out.println("INSTRUCTIONS:" +
                "Write a number in binary and it will be converted to base ten." +
                "Don't try to flip out my program I prevented you from writing 0 > n > 1");
       
        do { // repeat binary converter while user wants to
            do { // if user gives non-binary number, repeat
                System.out.println("Binary number: ");
                binaryStr = in.readLine();
                binary = binaryStr.toCharArray();
            }
            while(!isBinary());

            int digits = binary.length;
            int accum = 0;
            int add = 1; // the value of 2^n that i will add

            for (int i = 0; i < digits; i++)
                if (i > 0)
                    add = add * 2;
            for (int j = 0; j < digits; j++) {
                if (binary[j] == '1')
                    accum += add;
                add = add / 2;
            }
         
            System.out.println("Binary: " + binaryStr + " = Base 10: " + accum);
            do { // if user doesn't give a valid answer, repeat
                System.out.println("Again? 1. Yes 2. No");
                decision = in.readInt();
            }
            while (decision != AGAIN && decision != END);
        }
        while (decision == AGAIN);
    }
}
« Last Edit: October 01, 2005, 06:42:02 pm by dynobird »

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #24 on: October 01, 2005, 06:38:05 pm »
It's sorta long but it has good explanations.
I'm listening.  This thread is too on-topic!  Let's change that.  :)

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #25 on: October 01, 2005, 11:34:17 pm »
Well Sidoh, its hard to take a programming discussion off-topic when the only people who can understand a word we're saying are programmers who wouldn't want to take this off-topic. On a side note, so we don't go off-topic..

joe@JoeMomma:~/dev/cpp/helloworld $ ./binconv-rev && ./binconv
Enter decimal number:
125
125 = 01111101b
Enter binary digits:
01111101
01111101b = 125


Thanks to iago's C++ binary bot, I figured out strings.
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Ergot

  • 吴立峰 ^_^ !
  • x86
  • Hero Member
  • *****
  • Posts: 3724
  • I steal bandwidth. p_o
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #26 on: October 01, 2005, 11:48:49 pm »
Nice lol. LIBERATE THE SOURCE! It's for me to study ;S
Who gives a damn? I fuck sheep all the time.
And yes, male both ends.  There are a couple lesbians that need a two-ended dildo...My router just refuses to wear a strap-on.
(05:55:03) JoE ThE oDD: omfg good job i got a boner thinkin bout them chinese bitches
(17:54:15) Sidoh: I love cosmetology

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #27 on: October 02, 2005, 02:09:40 am »
Code: [Select]
// C++ binary->decimal converter
// Author: Joe[e2]

#include <iostream.h>
#include <stdio.h>
using namespace std;

int main() {
  string binary;
  int accum = 0;
  int add = 255;

  printf("Enter binary digits:\n");
  cin >> binary;
  add = 128;
  for(int i = 0; i < 8; i++) {
    if(binary.substr(i, 1) == "1") { accum = accum + add; }
    add = add / 2;
  }

  cout << binary << "b = " << accum << "\n";
  return 0;
}

That makes a horrible asumption that the string's length is always 8, but it also handles the error of it being more than 8, by only using the first 8. I don't know how C++ would handle me trying, say, binary[999] when it only goes up to 7. Asuming it will return an 0x00 (which isn't an 0x31), it will test as a "0".

EDIT -
joe@JoeMomma:~/dev/cpp/helloworld $ ./binconv
Enter binary digits:
10
Aborted

I didn't code that anywhere. Runtime error?
« Last Edit: October 02, 2005, 02:13:28 am by Joe[e2] »
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline rabbit

  • x86
  • Hero Member
  • *****
  • Posts: 8092
  • I speak for the entire clan (except Joe)
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #28 on: October 02, 2005, 02:25:49 pm »
Stop using stdio and iostream.  You're only meant to use ONE.

Offline drka

  • ffdshow > in_mp3.dll
  • Full Member
  • ***
  • Posts: 330
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #29 on: October 02, 2005, 02:28:35 pm »
i think scanf() works like cin

Offline Ergot

  • 吴立峰 ^_^ !
  • x86
  • Hero Member
  • *****
  • Posts: 3724
  • I steal bandwidth. p_o
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #30 on: October 02, 2005, 10:23:01 pm »
It does. That's why I use scanf().
Who gives a damn? I fuck sheep all the time.
And yes, male both ends.  There are a couple lesbians that need a two-ended dildo...My router just refuses to wear a strap-on.
(05:55:03) JoE ThE oDD: omfg good job i got a boner thinkin bout them chinese bitches
(17:54:15) Sidoh: I love cosmetology

Offline AntiVirus

  • Legendary
  • x86
  • Hero Member
  • *****
  • Posts: 2521
  • Best
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #31 on: October 03, 2005, 01:20:09 pm »
Code: [Select]
// C++ binary->decimal converter
// Author: Joe[e2]

#include <iostream.h>
#include <stdio.h>
using namespace std;

int main() {
  string binary;
  int accum = 0;
  int add = 255;

  printf("Enter binary digits:\n");
  cin >> binary;
  add = 128;
  for(int i = 0; i < 8; i++) {
    if(binary.substr(i, 1) == "1") { accum = accum + add; }
    add = add / 2;
  }

  cout << binary << "b = " << accum << "\n";
  return 0;
}

That makes a horrible asumption that the string's length is always 8, but it also handles the error of it being more than 8, by only using the first 8. I don't know how C++ would handle me trying, say, binary[999] when it only goes up to 7. Asuming it will return an 0x00 (which isn't an 0x31), it will test as a "0".

EDIT -
joe@JoeMomma:~/dev/cpp/helloworld $ ./binconv
Enter binary digits:
10
Aborted

I didn't code that anywhere. Runtime error?

I compiled your code with MSV C++ and I got these errors:
Quote
--------------------Configuration: Binary converter - Win32 Debug--------------------
Compiling...
Binary converter.cpp
u:\binary converter.cpp(6) : error C2871: 'std' : does not exist or is not a namespace
u:\binary converter.cpp(9) : error C2065: 'string' : undeclared identifier
u:\binary converter.cpp(9) : error C2146: syntax error : missing ';' before identifier 'binary'
u:\binary converter.cpp(9) : error C2065: 'binary' : undeclared identifier
u:\binary converter.cpp(17) : error C2228: left of '.substr' must have class/struct/union type
Error executing cl.exe.

Binary converter.obj - 5 error(s), 0 warning(s)

So, then I took the ".h" off the end of the #include <iostream.h> making it read #include <iostream> which brought me down to three errors:
Quote
--------------------Configuration: Binary converter - Win32 Debug--------------------
Compiling...
Binary converter.cpp
u:\binary converter.cpp(14) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion)
u:\binary converter.cpp(17) : error C2676: binary '==' : 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' does not define this operator or a conversion to a type acceptable to the predefined operator
u:\binary converter.cpp(21) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion)
Error executing cl.exe.

Binary converter.obj - 3 error(s), 0 warning(s)

And I don't know what to do from there. Right now.  I will look at if later if someone else doesn't figure it out first.

I hope that helps a little..
The once grove of splendor,
Aforetime crowned by lilac and lily,
Lay now forevermore slender;
And all winds that liven
Silhouette a lone existence;
A leafless oak grasping at eternity.


"They say that I must learn to kill before I can feel safe, but I rather kill myself then turn into their slave."
- The Rasmus

Offline Ergot

  • 吴立峰 ^_^ !
  • x86
  • Hero Member
  • *****
  • Posts: 3724
  • I steal bandwidth. p_o
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #32 on: October 03, 2005, 06:57:25 pm »

#include <stdio.h>
using namespace std;

int main() {
  string binary;
  int accum = 0;
  int add = 255;

  printf("Enter binary digits:\n");
  scanf("%s", binary); //might need a space in front of that % sign...
  add = 128;
  for(int i = 0; i < 8; i++) {
    if(binary.substr(i, 1) = "1") { accum = accum + add; }
    add = add / 2;
  }

  printf("%sb = %d\n",binary, accum);
  return 0;
}

just off the top of my head... to get rid of iostream all together... I nevered used it... doesn't seem necessary for now...
Who gives a damn? I fuck sheep all the time.
And yes, male both ends.  There are a couple lesbians that need a two-ended dildo...My router just refuses to wear a strap-on.
(05:55:03) JoE ThE oDD: omfg good job i got a boner thinkin bout them chinese bitches
(17:54:15) Sidoh: I love cosmetology

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #33 on: October 04, 2005, 07:30:40 am »
Brandon, might want to look into a Win32 port of g++.

EDIT -
http://www.mingw.org/
« Last Edit: October 04, 2005, 07:32:57 am by Joe[e2] »
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline AntiVirus

  • Legendary
  • x86
  • Hero Member
  • *****
  • Posts: 2521
  • Best
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #34 on: October 04, 2005, 09:21:29 pm »
Brandon, might want to look into a Win32 port of g++.

EDIT -
http://www.mingw.org/
Okay, but I don't know what that is. :(

Will you explain a little?  I went to the site, and I didn't see anything about what you said.  I will keep looking, but will you still elaborate a little?

[Edit]
I read some more, and I am not sure if I found anything of use..  Maybe, I just don't understand what I am reading. (*sigh*)
« Last Edit: October 04, 2005, 09:24:13 pm by Brandon »
The once grove of splendor,
Aforetime crowned by lilac and lily,
Lay now forevermore slender;
And all winds that liven
Silhouette a lone existence;
A leafless oak grasping at eternity.


"They say that I must learn to kill before I can feel safe, but I rather kill myself then turn into their slave."
- The Rasmus

Offline Ergot

  • 吴立峰 ^_^ !
  • x86
  • Hero Member
  • *****
  • Posts: 3724
  • I steal bandwidth. p_o
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #35 on: October 04, 2005, 09:39:35 pm »
Me thinks it's a C++ compiler for Windows.
Who gives a damn? I fuck sheep all the time.
And yes, male both ends.  There are a couple lesbians that need a two-ended dildo...My router just refuses to wear a strap-on.
(05:55:03) JoE ThE oDD: omfg good job i got a boner thinkin bout them chinese bitches
(17:54:15) Sidoh: I love cosmetology

Offline AntiVirus

  • Legendary
  • x86
  • Hero Member
  • *****
  • Posts: 2521
  • Best
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #36 on: October 04, 2005, 09:43:29 pm »
Okay, that would make since.  But, why would he tell me to look at it?  Is MSV C++ bad? 
The once grove of splendor,
Aforetime crowned by lilac and lily,
Lay now forevermore slender;
And all winds that liven
Silhouette a lone existence;
A leafless oak grasping at eternity.


"They say that I must learn to kill before I can feel safe, but I rather kill myself then turn into their slave."
- The Rasmus

Offline Ergot

  • 吴立峰 ^_^ !
  • x86
  • Hero Member
  • *****
  • Posts: 3724
  • I steal bandwidth. p_o
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #37 on: October 04, 2005, 10:16:19 pm »
He would think so if it doesn't compile his code.
Who gives a damn? I fuck sheep all the time.
And yes, male both ends.  There are a couple lesbians that need a two-ended dildo...My router just refuses to wear a strap-on.
(05:55:03) JoE ThE oDD: omfg good job i got a boner thinkin bout them chinese bitches
(17:54:15) Sidoh: I love cosmetology

Offline drka

  • ffdshow > in_mp3.dll
  • Full Member
  • ***
  • Posts: 330
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #38 on: October 05, 2005, 12:33:02 am »
if mingw cant compile managed code, then it sucks

Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #39 on: October 05, 2005, 01:08:27 am »
He would think so if it doesn't compile his code.

If he coded correctly (like using #include <stdio> or #include <iostream> as opposed to #include <stdio.h> and #include <iostream.h>), and maybe only used one I/O header, he might be better-off.  :P
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline Ergot

  • 吴立峰 ^_^ !
  • x86
  • Hero Member
  • *****
  • Posts: 3724
  • I steal bandwidth. p_o
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #40 on: October 05, 2005, 01:35:21 am »
I use #include <stdio.h> :( I should fix that ;O !
Who gives a damn? I fuck sheep all the time.
And yes, male both ends.  There are a couple lesbians that need a two-ended dildo...My router just refuses to wear a strap-on.
(05:55:03) JoE ThE oDD: omfg good job i got a boner thinkin bout them chinese bitches
(17:54:15) Sidoh: I love cosmetology

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #41 on: October 05, 2005, 05:42:28 pm »
Heh, use the GNU C++ compiler. If it doesn't work with GNU, its broken!
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline rabbit

  • x86
  • Hero Member
  • *****
  • Posts: 8092
  • I speak for the entire clan (except Joe)
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #42 on: October 05, 2005, 06:06:40 pm »
Or you're lazy.

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #43 on: October 05, 2005, 06:19:42 pm »
GNU is the best. GNU rocks. <3 GNU. If I were lazy, this topic wouldn't exist. What C++ compiler should I aim to have this work with? M$VC? Right, well, I'll go pay a thousand dollars for software I use as a hobby. Wait.. The GNU C++ compiler is free. Bingo!
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline AntiVirus

  • Legendary
  • x86
  • Hero Member
  • *****
  • Posts: 2521
  • Best
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #44 on: October 05, 2005, 06:28:57 pm »
Well, I already have the software.. so I am just going to stick with MsV C++ ;)
The once grove of splendor,
Aforetime crowned by lilac and lily,
Lay now forevermore slender;
And all winds that liven
Silhouette a lone existence;
A leafless oak grasping at eternity.


"They say that I must learn to kill before I can feel safe, but I rather kill myself then turn into their slave."
- The Rasmus

Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #45 on: October 05, 2005, 08:03:51 pm »
GNU is the best. GNU rocks. <3 GNU. If I were lazy, this topic wouldn't exist. What C++ compiler should I aim to have this work with? M$VC? Right, well, I'll go pay a thousand dollars for software I use as a hobby. Wait.. The GNU C++ compiler is free. Bingo!

Or, maybe, if you actually coded correctly, it would work on either one, Mr. Cross-Platform Compatibility.

For example, this page talks about the differences between ISO C (C99) and ISO C++ (C++98).  Throughout the document, #include <iostream> is used; never once is #include <iostream.h>

Also, information about the ANSI C++ Standard specifically talks about header files (in order to support precompiled headers):
Quote
Header file names no longer maintain the .h extension typical of the C language and of pre-standard C++ compilers, as in the case of stdio.h, stdlib.h, iostream.h, etc. This extension h simply disappears and files previously known as iostream.h become iostream (without .h).

Also Joe, MSVC++ 2003 compiler and platform SDK are also free.

Logic defeats counter-culture *nix-ism again! G_G
« Last Edit: October 06, 2005, 01:44:48 am by MyndFyre[x86] »
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline drka

  • ffdshow > in_mp3.dll
  • Full Member
  • ***
  • Posts: 330
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #46 on: October 06, 2005, 01:12:57 am »
haha i was about to say that the MSVC++ compiler is free.

btw:for those of you who dont know where to dl it, search google for Microsoft Visual C++ Toolkit 2003. im in love with it since it can compile managed code.

Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #47 on: October 06, 2005, 01:44:25 am »
btw:for those of you who dont know where to dl it, search google for Microsoft Visual C++ Toolkit 2003. im in love with it since it can compile managed code.
Or: you could click the link that I provided above, "MSVC++ 2003 compiler and platform SDK".
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #48 on: October 06, 2005, 06:58:45 pm »
And this topic is officially dead.
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline rabbit

  • x86
  • Hero Member
  • *****
  • Posts: 8092
  • I speak for the entire clan (except Joe)
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #49 on: October 06, 2005, 08:18:42 pm »
GNU is the best. GNU rocks. <3 GNU. If I were lazy, this topic wouldn't exist. What C++ compiler should I aim to have this work with? M$VC? Right, well, I'll go pay a thousand dollars for software I use as a hobby. Wait.. The GNU C++ compiler is free. Bingo!
My point was that if it doesn't work with the GNU compiler you obviously suck at life because the GNU compiler will compile any code that's valid.

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #50 on: October 06, 2005, 10:12:10 pm »
And the GNU compiler compiles my code, so theres nothing to worry about.
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline drka

  • ffdshow > in_mp3.dll
  • Full Member
  • ***
  • Posts: 330
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #51 on: October 07, 2005, 12:35:08 am »
btw:for those of you who dont know where to dl it, search google for Microsoft Visual C++ Toolkit 2003. im in love with it since it can compile managed code.
Or: you could click the link that I provided above, "MSVC++ 2003 compiler and platform SDK".
i didnt realize that it was a link :P. i can barely see any links with this skin

Offline AntiVirus

  • Legendary
  • x86
  • Hero Member
  • *****
  • Posts: 2521
  • Best
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #52 on: October 07, 2005, 11:31:57 am »
Time for a new skin.. ^^;
The once grove of splendor,
Aforetime crowned by lilac and lily,
Lay now forevermore slender;
And all winds that liven
Silhouette a lone existence;
A leafless oak grasping at eternity.


"They say that I must learn to kill before I can feel safe, but I rather kill myself then turn into their slave."
- The Rasmus

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #53 on: October 15, 2005, 11:36:25 pm »
joe@JoeMomma:~/dev/cpp/ascii $ cat ./main.cpp
// Ascii Chart
// Author: Joe[e2]

#include <iostream>
using namespace std;

int main() {
  char character; int i2;
  for(int i=0x11; i<0x100; i=i+5) {
    for(i2=1; i2<6; i2++) {
      if(i2+i+1 >= 0x100) {
      } else {
        character = i2+i+1;
        cout << "0x" << hex << i2+i+1 << " == " << character << "   ";
      }
    }
    cout << endl;
  }
  return 0;
}


joe@JoeMomma:~/dev/cpp/ascii $ g++ -o main.o main.cpp && ./main.o
0x13 ==    0x14 ==    0x15 ==    0x16 ==    0x17 == 
0x18 ==    0x19 ==    0x1a ==    0x1b ==    0x1c == 
0x1d ==    0x1e ==    0x1f ==    0x20 ==     0x21 == !
0x22 == "   0x23 == #   0x24 == $   0x25 == %   0x26 == &
0x27 == '   0x28 == (   0x29 == )   0x2a == *   0x2b == +
0x2c == ,   0x2d == -   0x2e == .   0x2f == /   0x30 == 0
0x31 == 1   0x32 == 2   0x33 == 3   0x34 == 4   0x35 == 5
0x36 == 6   0x37 == 7   0x38 == 8   0x39 == 9   0x3a == :
0x3b == ;   0x3c == <   0x3d == =   0x3e == >   0x3f == ?
0x40 == @   0x41 == A   0x42 == B   0x43 == C   0x44 == D
0x45 == E   0x46 == F   0x47 == G   0x48 == H   0x49 == I
0x4a == J   0x4b == K   0x4c == L   0x4d == M   0x4e == N
0x4f == O   0x50 == P   0x51 == Q   0x52 == R   0x53 == S
0x54 == T   0x55 == U   0x56 == V   0x57 == W   0x58 == X
0x59 == Y   0x5a == Z   0x5b == [   0x5c == \   0x5d == ]
0x5e == ^   0x5f == _   0x60 == `   0x61 == a   0x62 == b
0x63 == c   0x64 == d   0x65 == e   0x66 == f   0x67 == g
0x68 == h   0x69 == i   0x6a == j   0x6b == k   0x6c == l
0x6d == m   0x6e == n   0x6f == o   0x70 == p   0x71 == q
0x72 == r   0x73 == s   0x74 == t   0x75 == u   0x76 == v
0x77 == w   0x78 == x   0x79 == y   0x7a == z   0x7b == {
0x7c == |   0x7d == }   0x7e == ~   0x7f ==    0x80 == &#128;
0x81 == ?   0x82 == &#130;   0x83 == &#131;   0x84 == &#132;   0x85 == &#133;
0x86 == &#134;   0x87 == &#135;   0x88 == &#136;   0x89 == &#137;   0x8a == &#138;
0x8b == &#139;   0x8c == &#140;   0x8d == ?   0x8e == &#142;   0x8f == ?
0x90 == ?   0x91 == &#145;   0x92 == &#146;   0x93 == &#147;   0x94 == &#148;
0x95 == &#149;   0x96 == &#150;   0x97 == &#151;   0x98 == &#152;   0x99 == &#153;
0x9a == &#154;   0x9b == &#155;   0x9c == &#156;   0x9d == ?   0x9e == &#158;
0x9f == &#159;   0xa0 ==     0xa1 == ¡   0xa2 == ¢   0xa3 == £
0xa4 == ¤   0xa5 == ¥   0xa6 == ¦   0xa7 == §   0xa8 == ¨
0xa9 == ©   0xaa == ª   0xab == «   0xac == ¬   0xad == ­
0xae == ®   0xaf == ¯   0xb0 == °   0xb1 == ±   0xb2 == ²
0xb3 == ³   0xb4 == ´   0xb5 == µ   0xb6 == ¶   0xb7 == ·
0xb8 == ¸   0xb9 == ¹   0xba == º   0xbb == »   0xbc == ¼
0xbd == ½   0xbe == ¾   0xbf == ¿   0xc0 == À   0xc1 == Á
0xc2 ==    0xc3 == à  0xc4 == Ä   0xc5 == Å   0xc6 == Æ
0xc7 == Ç   0xc8 == È   0xc9 == É   0xca == Ê   0xcb == Ë
0xcc == Ì   0xcd == Í   0xce == Π  0xcf == Ï   0xd0 == Ð
0xd1 == Ñ   0xd2 == Ò   0xd3 == Ó   0xd4 == Ô   0xd5 == Õ
0xd6 == Ö   0xd7 == ×   0xd8 == Ø   0xd9 == Ù   0xda == Ú
0xdb == Û   0xdc == Ü   0xdd == Ý   0xde == Þ   0xdf == ß
0xe0 == à   0xe1 == á   0xe2 == â   0xe3 == ã   0xe4 == ä
0xe5 == å   0xe6 == æ   0xe7 == ç   0xe8 == è   0xe9 == é
0xea == ê   0xeb == ë   0xec == ì   0xed == í   0xee == î
0xef == ï   0xf0 == ð   0xf1 == ñ   0xf2 == ò   0xf3 == ó
0xf4 == ô   0xf5 == õ   0xf6 == ö   0xf7 == ÷   0xf8 == ø
0xf9 == ù   0xfa == ú   0xfb == û   0xfc == ü   0xfd == ý
0xfe == þ   0xff == ÿ
« Last Edit: October 15, 2005, 11:37:57 pm by Joe[e2] »
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #54 on: October 16, 2005, 01:25:09 am »
I have created the UGLIEST loop ever. An array of 13 ints (which isn't even an array) in imbeded for statments, to create every single possible CD-Key. C++, or manual labor?

Ergot, beat this or go pump gas~.

joe@JoeMomma:~/dev/cpp/sckmg $ g++ -o SCKMG main.cpp && ./SCKMG
SCKMG by Joe[e2] loaded.
Valid key: 0000000000003
Valid key: 0000000000014
Valid key: 0000000000021
Valid key: 0000000000032
Valid key: 0000000000047
Valid key: 0000000000058
Valid key: 0000000000065
Valid key: 0000000000076
Valid key: 0000000000081
Valid key: 0000000000092
Valid key: 0000000000106
Valid key: 0000000000117
Valid key: 0000000000128
Valid key: 0000000000139
Valid key: 0000000000142
Valid key: 0000000000153
Valid key: 0000000000164
Valid key: 0000000000175
Valid key: 0000000000184
Valid key: 0000000000195
Valid key: 0000000000207
Valid key: 0000000000218
Valid key: 0000000000225
Valid key: 0000000000236
Valid key: 0000000000243
Valid key: 0000000000254
Valid key: 0000000000261
Valid key: 0000000000272
Valid key: 0000000000289
Valid key: 0000000000290
Valid key: 0000000000300
Valid key: 0000000000311
Valid key: 0000000000322
Valid key: 0000000000333
Valid key: 0000000000344
Valid key: 0000000000355
Valid key: 0000000000366
Valid key: 0000000000377
Valid key: 0000000000388
Valid key: 0000000000399
Valid key: 0000000000401
Valid key: 0000000000412
Valid key: 0000000000429
Valid key: 0000000000430
Valid key: 0000000000445
Valid key: 0000000000456
Valid key: 0000000000463
Valid key: 0000000000474
Valid key: 0000000000483
Valid key: 0000000000494
Valid key: 0000000000504
Valid key: 0000000000515
Valid key: 0000000000526
Valid key: 0000000000537
Valid key: 0000000000540
Valid key: 0000000000551
Valid key: 0000000000562
Valid key: 0000000000573
Valid key: 0000000000586
Valid key: 0000000000597
Valid key: 0000000000605
Valid key: 0000000000616
Valid key: 0000000000623
Valid key: 0000000000634
Valid key: 0000000000641
Valid key: 0000000000652
Valid key: 0000000000669
Valid key: 0000000000670
Valid key: 0000000000683
Valid key: 0000000000694
Valid key: 0000000000708
Valid key: 0000000000719
Valid key: 0000000000720
Valid key: 0000000000731
Valid key: 0000000000742
Valid key: 0000000000753
Valid key: 0000000000764
Valid key: 0000000000775
Valid key: 0000000000780
Valid key: 0000000000791
Valid key: 0000000000807
Valid key: 0000000000818
Valid key: 0000000000825
Valid key: 0000000000836
Valid key: 0000000000841
Valid key: 0000000000852
Valid key: 0000000000869
Valid key: 0000000000870
Valid key: 0000000000885
Valid key: 0000000000896
Valid key: 0000000000900
Valid key: 0000000000911
Valid key: 0000000000922
Valid key: 0000000000933
Valid key: 0000000000946
Valid key: 0000000000957
Valid key: 0000000000968
Valid key: 0000000000979
Valid key: 0000000000988
Valid key: 0000000000999
Valid key: 0000000001002
Valid key: 0000000001013
Valid key: 0000000001024
Valid key: 0000000001035
Valid key: 0000000001046
Valid key: 0000000001057
Valid key: 0000000001068
Valid key: 0000000001079
Valid key: 0000000001084
Valid key: 0000000001095
Valid key: 0000000001105
Valid key: 0000000001116
Valid key: 0000000001123
Valid key: 0000000001134
Valid key: 0000000001149
Valid key: 0000000001150
Valid key: 0000000001167
Valid key: 0000000001178
Valid key: 0000000001187
Valid key: 0000000001198
Valid key: 0000000001208
Valid key: 0000000001219
Valid key: 0000000001220
Valid key: 0000000001231
Valid key: 0000000001244
Valid key: 0000000001255
Valid key: 0000000001266
Valid key: 0000000001277
Valid key: 0000000001280
Valid key: 0000000001291
Valid key: 0000000001301
Valid key: 0000000001312
Valid key: 0000000001329
Valid key: 0000000001330
Valid key: 0000000001347
Valid key: 0000000001358
Valid key: 0000000001365
Valid key: 0000000001376
Valid key: 0000000001383
Valid key: 0000000001394
Valid key: 0000000001404
Valid key: 0000000001415
Valid key: 0000000001426
Valid key: 0000000001437
Valid key: 0000000001448
Valid key: 0000000001459
Valid key: 0000000001460
Valid key: 0000000001471
Valid key: 0000000001482
Valid key: 0000000001493
Valid key: 0000000001507
Valid key: 0000000001518
Valid key: 0000000001525
Valid key: 0000000001536
Valid key: 0000000001541
Valid key: 0000000001552
Valid key: 0000000001569
Valid key: 0000000001570
Valid key: 0000000001585


By the way, theres more valid keys out there. I just didn't want to make too big of a post.
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Newby

  • Moderator
  • Hero Member
  • *****
  • Posts: 10877
  • Thrash!
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #55 on: October 16, 2005, 02:35:01 am »
if mingw cant compile managed code, then it sucks

Would you mind telling me the differences (technical) between managed code, and unmanaged code, since you seem to know so much about managed code and its benefits and why compilers should be able to compile it?
- Newby
http://www.x86labs.org

Quote
[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

I'd bet that you're currently bloated like a water ballon on a hot summer's day.

That analogy doesn't even make sense.  Why would a water balloon be especially bloated on a hot summer's day? For your sake, I hope there wasn't too much logic testing on your LSAT. 

Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #56 on: October 16, 2005, 05:25:19 am »
if mingw cant compile managed code, then it sucks

Would you mind telling me the differences (technical) between managed code, and unmanaged code, since you seem to know so much about managed code and its benefits and why compilers should be able to compile it?
You're asking him to do it specifically, right?  I'm not allowed to?
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline Newby

  • Moderator
  • Hero Member
  • *****
  • Posts: 10877
  • Thrash!
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #57 on: October 16, 2005, 01:07:37 pm »
You're asking him to do it specifically, right?  I'm not allowed to?

Nope! Mangix seems to be intelligent on the subject, and I am not, so I'd like to be enlightened as to how it works. :)
- Newby
http://www.x86labs.org

Quote
[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

I'd bet that you're currently bloated like a water ballon on a hot summer's day.

That analogy doesn't even make sense.  Why would a water balloon be especially bloated on a hot summer's day? For your sake, I hope there wasn't too much logic testing on your LSAT. 

Offline drka

  • ffdshow > in_mp3.dll
  • Full Member
  • ***
  • Posts: 330
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #58 on: October 16, 2005, 02:01:18 pm »
if mingw cant compile managed code, then it sucks

Would you mind telling me the differences (technical) between managed code, and unmanaged code, since you seem to know so much about managed code and its benefits and why compilers should be able to compile it?
Managed code is just C++ with Managed Extensions or C++ .NET(even though Microsoft didnt do anything to the language(i think)).

Unmanaged code is regular code that doesnt use .NET Namespaces but instead uses functions and other stuff from #includes just like Joe has been doing

And the reason that i think all compilers should compile it is because even though it uses .NET, it's still C++(and you can write managed code with unmanaged code which is kinda fun)

Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #59 on: October 17, 2005, 02:33:49 am »
That's one of the most incomplete responses EVER!
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline drka

  • ffdshow > in_mp3.dll
  • Full Member
  • ***
  • Posts: 330
    • View Profile
Re: [C/C++] Joe vs Ergot: Code wars!
« Reply #60 on: October 17, 2005, 06:46:50 pm »
Thanks!