William Hemsworth 1,339 Posting Virtuoso

'\n' is simply equivalent to a newline, you could have easily replaced it outside the qoutes as endl as you have done with the other lines if you had wanted.. it was just easier to do that :icon_wink: .

William Hemsworth 1,339 Posting Virtuoso

Woo! you did it without anybody writing the code for you.. (it's a nice change)
but, here are just a few final touches to it.. along with formatting it for you (for the second time)

#include <iostream> 
using namespace std; 

int add(int x, int y) {
  int r;
  r = x + y;
  return(r); 
}  

int main () { 
  int x, y;

  cout << "Welcome to the Functions Program! To quit enter 0." << endl;
  cout << "Input two numbers." << endl;
  cin >> x >> y;

  while (x != 0 || y != 0) {
    int [B]z = add(x, y);[/B] 
    cout << "The result is " << z;  
    cout << "[B]\n[/B]Would you like to continue? If so enter another two numbers, if not enter 0" << endl;
    cin >> x >> y ; 
  }
}
Alex Edwards commented: Yes! Whoo Indeed! O_O +5
William Hemsworth 1,339 Posting Virtuoso

Okay, now its happening alot more often (at least 50% of the time).. and its beginning to get quite annoying. The last screenshot wasn't the best, so heres a better one. There's got to be a way you can fix this, isn't there some way for you to forse draw the menu's over the ads :) ?

William Hemsworth 1,339 Posting Virtuoso

A good effort :) (except for some of the formatting)
On line 23, would it be better to just replace that while with an if, as that way it will not run into an endless loop printing the result?

Change it from this: while (x != 0 || y != 0) { to: if (x != 0 || y != 0) { Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

Wow, Wow, Wow! Thanks for that :)

William Hemsworth 1,339 Posting Virtuoso

When things get this bad, honestly, just start over.
http://www.cplusplus.com/doc/tutorial/
Understand how to use functions and make simple expressions, also, keep your code well formatted. Here is how your current code would look well formatted, but all the mistakes are still there.

#include<iostream> 
using namespace std; 

int add(int x, int y) // your missing something here..

int main () 
{ 
  int x, y;
  cout << "Welcome to the Functions Program! To quit enter 00." << endl;
  cout << "Input two numbers." << endl;
  cin >> x, y;

  while (x != 00 || y != 00) // Padding with extra 0 changes the number base to octal, which I doubt you need here
  {
    int z; 
    z = add(x,y); 
    cout << "The result is " << z; 
    return 0; // Whats the point in the while loop, if this is here
  }

  int add(int x, int y) 
  {
    return (x+y); 
  } 
}

I have highlighted your mistakes, see if you can fix them.

Alex Edwards commented: Whoo! =) +5
Salem commented: Yeah, gotta watch those octal zeros, they're a lot smaller than the decimal equivalents ;) +23
William Hemsworth 1,339 Posting Virtuoso

Gotchya..

William Hemsworth 1,339 Posting Virtuoso

It seems a little glitchy in some places. Sometimes the menu items seem to be covered up a little by the ads, and menu's sometimes don't work for me. Ill try and get a screenshot for you.. but I always find it hard to redo the same glitch when im actually trying to find it ;)

William Hemsworth 1,339 Posting Virtuoso

So, guys, stop crying about the old stuff, take a look around, nothing is the same - this change is for good.

I have already looked around, and have decided I prefer the old one, what more can I do :)?
I'm not 'crying', im simply pointing out what I think has turned out worse and whats turned out better.

So I don't think the story was quite necessary ;)

William Hemsworth 1,339 Posting Virtuoso

Haha, this made me laugh.. :D
But in many ways, they are correct (I still think its dumb though)

William Hemsworth 1,339 Posting Virtuoso

This question didn't make much sense to me at all.

> can I introduce something other than a 0 or a 1 in a bit?
A bit can only be either a 1 or a 0, or you can think of it as either on or off.

William Hemsworth 1,339 Posting Virtuoso

Learn how to use code-tags.

William Hemsworth 1,339 Posting Virtuoso

Thats amazing :)

William Hemsworth 1,339 Posting Virtuoso

double doesn't support the Modulus operator, you will have to implement it yourself if you want to do this.

William Hemsworth 1,339 Posting Virtuoso

How about this, rather unusual method ;)

#include <iostream>

struct octet {
  union {
    char val;
    struct {
      unsigned h : 1;
      unsigned g : 1;
      unsigned f : 1;
      unsigned e : 1;
      unsigned d : 1;
      unsigned c : 1;
      unsigned b : 1;
      unsigned a : 1;
    };
  };
};

int main() {
  bool bits[] = {0, 1, 1, 0, 0, 0, 0, 1};

  octet o;
  o.a = bits[0];
  o.b = bits[1];
  o.c = bits[2];
  o.d = bits[3];
  o.e = bits[4];
  o.f = bits[5];
  o.g = bits[6];
  o.h = bits[7];

  std::cout << o.val; // 01100001 = 'a'
  std::cin.ignore();
}

Theres practically no maths involved :)

William Hemsworth 1,339 Posting Virtuoso

Oh Oh - STFW :) ... ( thanks for that niek! )

William Hemsworth 1,339 Posting Virtuoso

You need to buy one of this
http://gadgetmaniac.mail2web.com/wp-...42dwx-crvd.jpg

Holy crap! your right there :D


Take a look for yourself ;) The right monitor is about 10cm lower than the other.

William Hemsworth 1,339 Posting Virtuoso

Just drag your screen to the right

No can do :) I already use dual-display, meaning my main monitor is already on the left side of my desk,
making it even worse for me ^.^

William Hemsworth 1,339 Posting Virtuoso

Well, I wont be happy until the post alignment is back to the middle.
But I guess I will have to live with that :icon_neutral:

William Hemsworth 1,339 Posting Virtuoso

Of course you can easily crash Windows with Win32 api, but what's the goal ?
It's stupid.

Your beginning to get on my nerves..
If you read his post, you would have noticed he said he was just curious. For all you know, he could have been trying to understand how it works to prevent other applications from doing the same. Think before you post.. and don't just suddenly jump to the conclusion that "It's stupid".

William Hemsworth 1,339 Posting Virtuoso

I will be honest, I don't like it as much as the old one, though I'm pretty sure other people do :) I don't like having all the posts crammed on the left side of the page. Instead, I prefer to have them aligned in the centre like the old style did.

Do you think its possible to add an option in the control panel to switch back to the old layout?
Just for those of us who don't like change :P

William Hemsworth 1,339 Posting Virtuoso

>Deliberately crashing the kernel isn't funny
Does that mean accidently crashing it is? :)

Hah :D , sorry, I coulden't help myself.

Alex Edwards commented: Whoo! =P +5
William Hemsworth 1,339 Posting Virtuoso

>I was just curious, I absolutely do not want to make any type of virus, trojan, or malware.

I have to admit, I believe you (because i've helped you in many previous threads). And well, we all find ammusment in differen't things, making pranks for a friend (as long as it doesn't damage their system like Duoas said) isn't too bad if it gives a couple of laughs. It will be possible, but I don't know any ways of doing it off the top of my head. Just.. don't over-do it :)

William Hemsworth 1,339 Posting Virtuoso

Was it really necessary to post 1126 lines of code, especially with a very vague question..

William Hemsworth 1,339 Posting Virtuoso

The file is available at compilation time.. but not run time. As far as I can think, the only way this is possible is to use the #include directive, assuming the file contains C/C++ code. Other than that, I have no idea :)

William Hemsworth 1,339 Posting Virtuoso

:sweat: Eesh, I was just thinking today how I seemed to be getting so much more spam than usual.

Damn?..

Alex Edwards commented: That sucks >_< +5
William Hemsworth 1,339 Posting Virtuoso

Backdoorish? :)
Put it this way, why would they have added the functionality to the Picture Control to detect mouse-clicks, if it didn't work? (assuming they did). Don't try and do something the harder way, before you check if theres an easier, perfectly well-working solution already there for you :icon_cheesygrin:

William Hemsworth 1,339 Posting Virtuoso

Sorry for taking so long, i've had some net / pc problems. This looks like quite a big code, so im not going to go into finding an exact solution. But, I could suggest you use a Picture Control, set the bitmap for it to display, and try to detect a mouse-click on it (by making it notify the parent), well.. thats how I would do it anyway ;) . Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

This is one of those situations where, as long as the project isn't too big and it is okay with you, attach the whole thing and let me have a little play around with it to see if I can figure it out :) Im sure the problem is easier to solve than it appears.

William Hemsworth 1,339 Posting Virtuoso

Please don't PM me for help.

error C2664: 'strlen' : cannot convert parameter 1 from 'std::string *' to 'const char *'

To fix this error, try to understand what exactly is wrong. You are passing the datatype std::string* to the function strlen, which will ONLY accept the datatype const char*.

bool operator ==(cars& any, cars& mercedes) {
   int k;
   for (k = 0; k < (strlen(mercedes.mj)); k++) {
      return (any.me[k] == mercedes.mj[k]);
   }
}

As you are using std::string's, I see no appropriate reason to use the strlen function as there is already a .length() member as part of the std::string class. Also, mercedes.mj appears to be a pointer to an std::string, so as long as the pointer is valid, you can find the length of the string like this:

mercedes.mj->length()

And when applied to your code, this should work:

bool operator ==(cars& any, cars& mercedes) {
   int k;
   for (k = 0; k < mercedes.mj->length(); k++) {
      return (any.me[k] == mercedes.mj[k]);
   }
}

Then I also realized, though it isn't causing any errors, this line is also wrong.

return (any.me[k] == mercedes.mj[k]);

Both any.me and mercedes.mj are pointers to std::string's, therefore you should use the * operator. Here is how the whole corrected function should look:

bool operator ==(cars& any, cars& mercedes) {
   int k;
   for (k = 0; k < mercedes.mj->length(); k++) {
      return ((*any.me)[k] == (*mercedes.mj)[k]);
   }
}

However, I get this horrible feeling that …

William Hemsworth 1,339 Posting Virtuoso

>i seriously tried but still cannot find the mistake
Huh? What do you mean you can't find it? You have been told exactly what your error is, and how to solve it. What more could you want?

Read through the posts, and actually pay attention to what is being said. :icon_rolleyes:

William Hemsworth 1,339 Posting Virtuoso
William Hemsworth 1,339 Posting Virtuoso

Is this what your looking for :)?

#include <iostream>
#include <fstream>

int main() 
{
    char level[10][10]; // [x][y]

    std::ifstream infile("level.txt"); // open
    char ch; // Temp char

    // What now?   -->  Read it manually
    for (int y = 0; y < 10; ++y) {
       for (int x = 0; x < 10; ++x) {
          infile.get(ch);
          if (ch != '\n') {
             level[x][y] = ch;
          } else {
             --x;
             continue;
          }
       }
    }

    // Display the map
    for (int y = 0; y < 10; ++y) {
       for (int x = 0; x < 10; ++x) {
          std::cout << level[x][y];
       }
       std::cout << '\n';
    }

    infile.close(); // close
    std::cin.ignore();
}
William Hemsworth 1,339 Posting Virtuoso

>the last char of std::string value is not equal to 0.
Yes it is :icon_neutral: It is the null terminator, every std::string finishes with one.

And, try typing "HowManyPhantomZeroesPushed:1-2-3-4-5..." in the longer solution, I can assure you it isn't much better :)

William Hemsworth 1,339 Posting Virtuoso

>here a solution to your problem
That is a very long and overcomplex solution to his problem I think :) Heres my solution.

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

int main() {
   string value;
   cout << "Please input something: ";
   getline(cin, value);

   vector<int> numbers;
   int temp = 0;

   for (size_t i = 0;; ++i)  {
      if (isdigit(value[i])) {
         temp *= 10;
         temp += value[i] - '0';
      } else {
         numbers.push_back(temp);
         temp = 0;
      }
      if (value[i] == 0) {
         break;
      }
   }

   for (size_t i = 0; i < numbers.size(); ++i) {
      cout << "Number " << (i+1) << ": " << numbers[i] << endl;
   }

   cin.ignore();
   return 0;
}
William Hemsworth 1,339 Posting Virtuoso

>I suppose I'll revive this thread =)
Wow, what is the chance of that?! :icon_lol: , I was just about to do that.. seriously ^.^

Another chance to go back to Portugal & meet up with my family and friends again (its not gonna happen) :)

Alex Edwards commented: I hope everything works out for you! =) +4
William Hemsworth 1,339 Posting Virtuoso

Saving and loading maps coulden't be easier with C++ :) Say you have your map in a char array, this code would save that array to a bitmap.

#include <iostream>
#include <fstream>

int main() {
   char map[] = {
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 1, 1, 1, 1, 1, 1, 1, 1, 0,
       0, 1, 1, 1, 1, 1, 1, 1, 1, 0,
       0, 1, 1, 1, 1, 1, 1, 1, 1, 0,
       0, 1, 1, 1, 1, 1, 1, 1, 1, 0,
       0, 1, 1, 1, 1, 1, 1, 1, 1, 0,
       0, 1, 1, 1, 1, 1, 1, 1, 1, 0,
       0, 1, 1, 1, 1, 1, 1, 1, 1, 0,
       0, 1, 1, 1, 1, 1, 1, 1, 1, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   };

   std::ofstream out("level.txt"); // Open stream
   out.write(map, sizeof( map )); // Write data
   out.close(); // Close stream
}

Then reading it is just as easy, except for the fact that you need to know how big the map will be before reading it, but in this case, it will just be 100:

#include <iostream>
#include <fstream>

int main() {
   char map[100];
   std::ifstream in("level.txt"); // Open stream
   in.read(map, sizeof( map )); // Read data from file
   in.close(); // Close stream
}

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

Your problem is very small :) The coordinate in which you are trying to display the menu is not based on the client location. Change your WM_RBUTTONUP message like this:

case WM_RBUTTONUP: 
   POINT p;
   p.x = LOWORD(lParam);
   p.y = HIWORD(lParam);
   ClientToScreen(hWnd, &p);
   DisplayPopupMenu(p.x, p.y);
   break;

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

Ewwhh.. :icon_confused:

William Hemsworth 1,339 Posting Virtuoso

Nope, hbrBackground only accepts HBRUSH, not an image. If you want to do this, you will have to draw it yourself. Try looking up the WM_PAINT and WM_ERASEBKGND messages, and manually paint the image on your parent window in your message handler. By posting some code, I could help more.

William Hemsworth 1,339 Posting Virtuoso

uhh.. maybe you didn't understand the rules :)
Sun --> Us?

Antidisestablishmentarianism :icon_cheesygrin:

William Hemsworth 1,339 Posting Virtuoso

me too ;)

William Hemsworth 1,339 Posting Virtuoso

A few more, Links are to my favourite song by them :icon_cheesygrin:

Bowling for Soup
Michelle Branch
+44
Simple Plan
The Postal Service
The Rasmus
Zebrahead
Relient K
The Used
Bright Eyes
New Found Glory

William Hemsworth 1,339 Posting Virtuoso

>Aren't we supposed to just make 3 words from the word?
Its more fun to make more :)

Tired
Direct
Tied
Rot
Cot
Cry
Toe
Record
Dye
Tide

Digital

William Hemsworth 1,339 Posting Virtuoso

Maybe this thread will help you :) Link

William Hemsworth 1,339 Posting Virtuoso

840 on first try :)

William Hemsworth 1,339 Posting Virtuoso

Your way off :)

First of all you can't access a variable outside of its own scope, you are using the variable i in the function mystrlen, though it was created in the main function.

If you want to make the function mystrlen return the length of ptr, simply loop through each char until the null-char is reached, and return the index of that character. The change is simple.

int mystrlen(char *ptr) { 
   int i; // Length of ptr
   for (i = 0; ptr[i]; i++); // Loop until null-char is reached
   return i; // Return length
}

And then you could change your main function to:

int main() {
    char arr[] = "test";
    int num;

    num = mystrlen(arr);

    cout << "Print string text " << arr << endl; 
    cout << "Print string lenght: " << num;   

    return 0;
}

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

Now that i've had a better look at what you've got sofar, a way I think you could go about fixing this problem is by using the WM_ERASEBKGND message. By doing that all the notepad windows will be painted perfectly.
However, you are going to have to manually paint only the parts of the main window which don't have a notepad window over it (which may be harder than it sounds).

#include <windows.h>
#include <tchar.h>
const char ClassName[] = "WndClassName";
int counter = 0;
HWND notepad;
HWND notepad2;
HWND notepad3;

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
   switch (msg) {
      case WM_ERASEBKGND:
         {
            // Overridden
         }
         break;
      case WM_CLOSE:
         {
            DestroyWindow(hwnd);
         }
         break;

[B][..rest of code...][/B]

I will see what I can do :)

William Hemsworth 1,339 Posting Virtuoso

>but you didnt answer my Question !!
.. ehm, don't ask me, im 15 and haven't even done the mathematical constant e in class yet ;)

William Hemsworth 1,339 Posting Virtuoso

After 10 posts, have you still not figured out that your supposed to use code tags here?..