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

0 Members and 1 Guest are viewing this topic.

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