News:

Pretty crazy that we're closer to 2030, than we are 2005. Where did the time go!

Main Menu

[C/C++] Joe vs Ergot: Code wars!

Started by Joe, September 27, 2005, 07:26:53 PM

Previous topic - Next topic

0 Members and 3 Guests are viewing this topic.

Ergot

Quote from: Newby on February 26, 2006, 12:16:58 AM
Who gives a damn? I fuck sheep all the time.
Quote from: rabbit on December 11, 2005, 01:05:35 PM
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

AntiVirus

Quote from: Joe[e2] on October 02, 2005, 02:09:40 AM
// 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

Ergot


#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...
Quote from: Newby on February 26, 2006, 12:16:58 AM
Who gives a damn? I fuck sheep all the time.
Quote from: rabbit on December 11, 2005, 01:05:35 PM
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

Joe

#33
Brandon, might want to look into a Win32 port of g++.

EDIT -
http://www.mingw.org/
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


AntiVirus

#34
Quote from: Joe[e2] on October 04, 2005, 07:30:40 AM
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*)
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

Ergot

Me thinks it's a C++ compiler for Windows.
Quote from: Newby on February 26, 2006, 12:16:58 AM
Who gives a damn? I fuck sheep all the time.
Quote from: rabbit on December 11, 2005, 01:05:35 PM
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

AntiVirus

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

Ergot

He would think so if it doesn't compile his code.
Quote from: Newby on February 26, 2006, 12:16:58 AM
Who gives a damn? I fuck sheep all the time.
Quote from: rabbit on December 11, 2005, 01:05:35 PM
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

drka

if mingw cant compile managed code, then it sucks

MyndFyre

Quote from: Ergot on October 04, 2005, 10:16:19 PM
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
Quote from: Joe on January 23, 2011, 11:47:54 PM
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Quote from: Rule on May 26, 2009, 02:02:12 PMOur species really annoys me.

Ergot

I use #include <stdio.h> :( I should fix that ;O !
Quote from: Newby on February 26, 2006, 12:16:58 AM
Who gives a damn? I fuck sheep all the time.
Quote from: rabbit on December 11, 2005, 01:05:35 PM
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

Joe

Heh, use the GNU C++ compiler. If it doesn't work with GNU, its broken!
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


rabbit


Joe

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!
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


AntiVirus

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