William Hemsworth 1,339 Posting Virtuoso

Your going to have to be much more specific on your problem ;)
Post more details or code if possible.

William Hemsworth 1,339 Posting Virtuoso

I've had enough of people like you trying to cheat on or hack runescape, its totally pathetic. And you do know its illegal what your doing right? Look at 4th rule. link
And I dont care if your 13, its no excuse to do this sort of thing, Its time for you grow up and get a life.

Heres another typical example of somebody trying to cheat on Runescape, link... I could pretty much guarantee he quit after a couple of hours.

VernonDozier commented: Great link. +7
William Hemsworth 1,339 Posting Virtuoso

for (c = 0; c <= 5; c++) that counts from 0 to 6, not 0 to 5.

Depends, if you write it like this, it displays "012345", but c has the value 6 once its out the loop.

#include <iostream>
using namespace std;

int main() {
   int c;
   for (c = 0; c <= 5; c++) {
      cout << c;
   }
   cout << ' ' << c;
}

This gives the following output:

012345 6

I guess the quesion is only talking about what c is while its actually inside the loop ;)

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

hahaha xD!

William Hemsworth 1,339 Posting Virtuoso

Well.. whats your problem?
And, learn how to use code-tags.

William Hemsworth 1,339 Posting Virtuoso

Why didn't you just post the code?..

#include<stdio.h>
#include<conio.h>
#include<math.h>


float compute_amount(int kilowatt);
float compute_tax(float total);

void main()
{clrscr();
int kilowatt;
float Amount;
char decide;
do{
printf("Please enter your kilowatt: ");
scanf("%d",&kilowatt);
Amount=compute_amount(kilowatt);
printf("Your current Bill for this month is: %f\n\n",Amount);
printf("Do you want to repeat your transaction[Y or N]:  ");
scanf("\n");
scanf("%c",&decide);
}
while(decide=='y'||decide=='Y');
getch();
}

float compute_amount(int kilowatt)
{float total;

	total=(kilowatt-15)*20+(10)+compute_tax(total);
	return total;
}


float compute_tax(float total)
{float totalwtax,tax=0.05;

totalwtax=total+tax;

return totalwtax;
}

Now to fix it up a little.. Ive indented the code, added spaces where appropriate, and made main return an int.

#include <stdio.h>
#include <conio.h>
#include <math.h>

float compute_amount(int kilowatt);
float compute_tax(float total);

int main() {
   clrscr();
   int kilowatt;
   float Amount;
   char decide;
   do {
      printf("Please enter your kilowatt: ");
      scanf("%d",&kilowatt);
      Amount = compute_amount(kilowatt);
      printf("Your current Bill for this month is: %f\n\n",Amount);
      printf("Do you want to repeat your transaction[Y or N]:  ");
      scanf("\n");
      scanf("%c", &decide);
   } while (decide=='y'||decide=='Y');
   getch();
   return 0;
}

float compute_amount(int kilowatt) {
   float total;
   total = (kilowatt - 15) * 20 + 10 + compute_tax(total);
   return total;
}


float compute_tax(float total) {
   float totalwtax, tax = 0.05;
   totalwtax = total + tax;
   return totalwtax;
}
William Hemsworth 1,339 Posting Virtuoso
William Hemsworth 1,339 Posting Virtuoso

If you want to remove mutliple characters from the array, you can simply change it like this.

#include <iostream>

// Returns true if text contains ch
inline bool contains(char *text, char ch) {
   while (*text) {
      if (*text++ == ch) {
         return true;
      }
   }
   return false;
}

int main() {
   char arr[] = "abc  \n   \t\ndef";
   char spaces[] = " \t\n";

   // Create another array the same length as arr
   char temp[sizeof arr];

   // Index of where to insert character in new array
   int temp_index = 0;

   // Loop through each character until null-terminator is reached
   for (int i = 0; arr[i]; ++i) {
      if (!contains(spaces, arr[i])) {
         // Character isn't in the spaces array
         temp[temp_index++] = arr[i];
      }
   }

   // Add null-terminator
   temp[temp_index] = '\0';

   // Replace old array with new one
   strcpy_s(arr, sizeof(arr), temp);

   // Display the array
   std::cout << arr; // Outputs "abcdef"

   // Pause
   std::cin.ignore();
   return 0;
}

Now this will check to see if any of the char's in arr contain any of the char's in spaces, if it does, then it will remove them from the arr array.

William Hemsworth 1,339 Posting Virtuoso

Portability isn't too important when it comes to making a quick speed test, as I woulden't be keeping it that way. Either way, if the code didn't compile for you, I posted my output :)

>Depends. Maintainability (and readability) are pretty important in the real-world.
Thats true

William Hemsworth 1,339 Posting Virtuoso

Heres a nice place to start...
http://www.cplusplus.com/doc/tutorial/

William Hemsworth 1,339 Posting Virtuoso

ninwa's solution uses the same technique as mine, but using std::string's instead. Though it might be a better idea, it may overall be slower. Just to check, I did I little test.

ninwa's version:

#include <iostream>
using namespace std;

typedef unsigned __int64 uint64;

inline __declspec(naked) uint64 GetCycleCount() {
    _asm rdtsc;
    _asm ret;
}

int main() {
   uint64 cycle_timer_beg;
   uint64 cycle_timer_end;

   cycle_timer_beg = GetCycleCount();

   for (int j = 0; j < 10000; ++j) {

         char arr[] = {'a', 'b', 'c', ' ', ' ', ' ',
                       ' ', ' ', 'd', 'e', 'f', '\0'};
         string s(arr);
         string tmp = "";
         for (int i = 0; i < s.length(); i++) {
            if (s.at(i) != ' ') {
               tmp += s.at(i);
            }
         }
         s = tmp;

   }

   cycle_timer_end = GetCycleCount();

   cout << "Average cycle count: " << ((cycle_timer_end - cycle_timer_beg) / 10000);
   cin.ignore();
   return 0;
}

My version:

#include <iostream>
using namespace std;

typedef unsigned __int64 uint64;

inline __declspec(naked) uint64 GetCycleCount() {
    _asm rdtsc;
    _asm ret;
}

int main() {
   uint64 cycle_timer_beg;
   uint64 cycle_timer_end;

   cycle_timer_beg = GetCycleCount();

   for (int j = 0; j < 10000; ++j) {

      char arr[] = "abc     def";
      char temp[sizeof arr];
      int temp_index = 0;
      for (int i = 0; arr[i]; ++i) {
         if (arr[i] != ' ') {
            temp[temp_index++] = arr[i];
         }
      }
      temp[temp_index] = '\0';
      strcpy_s(arr, sizeof(arr), temp);

   }

   cycle_timer_end = GetCycleCount();

   cout << "Average cycle count: " << ((cycle_timer_end - cycle_timer_beg) / 10000);
   cin.ignore();
   return 0;
}

Hopefully this isn't going over the …

William Hemsworth 1,339 Posting Virtuoso

Well, a simple way to achieve this would be to create another array, the same length as arr, go through each character, and if that character isn't a space then copy it to the second array. Like this.

#include <iostream>

int main() {
   char arr[] = "abc     def";

   // Create another array the same length as arr
   char temp[sizeof arr];

   // Index of where to insert character in new array
   int temp_index = 0;

   // Loop through each character until null-terminator is reached
   for (int i = 0; arr[i]; ++i) {
      if (arr[i] != ' ') {
         // Character isn't a space
         temp[temp_index++] = arr[i];
      }
   }

   // Add null-terminator
   temp[temp_index] = '\0';

   // Replace old array with new one
   strcpy_s(arr, sizeof(arr), temp);

   // Display the array
   std::cout << arr;

   // Pause
   std::cin.ignore();
   return 0;
}

But if you wanted to achieve this without the need of a second array, its going to require a more complex algorithm. Hope this helps, and I also hope I haven't given too much away :)

William Hemsworth 1,339 Posting Virtuoso

haha :D This made me laugh.

William Hemsworth 1,339 Posting Virtuoso

You test may not be entirely accurate, for example in this part of the code:

for (int i = 0; i < 2000000; i++) {			
   stringstream v1(Num);
   v1 >> Number1;
}

Because here you are constructing stringstream 2000000 times, and destroying it 2000000 times, which obviously is going to add to the total amount of time, if you try making it a global or static variable, and just clear the stream every cycle, then hopefully this should speed it up. Like this:

double Number1;
std::string Num = "8.12";
stringstream v1;

for (int i = 0; i < 2000000; i++) {
   v1 << Num;
   v1 >> Number1;
   v1.clear();
}
William Hemsworth 1,339 Posting Virtuoso

Im aren't going to encourage cheating, and im certainly not going to give away code, this isn't the sort of thing that can be done in one night, you need to know some advanced C++ stuff, which im guessing you don't know. The only way this is going to get done is if you really put in alot of effort, stopped speaking in l33t sp33k and actually learned C++, that means buying book, reading tutorials and anything you can get your hands on. Personally I don't think you have a chance at succeeding in making this.

Im not* damn I hate this editing rule :idea:

William Hemsworth 1,339 Posting Virtuoso

>But hey i believe you, so i wont be able to make one ever?
I didn't say that ;)

I said it takes alot of effort, but of course you could make one if you really put your mind to it, but I just doubt you are willing to put in the amount of effort it takes to actually put this together.

>Any1 ever made on and can share it with me or any1 than says, ohh easy i can make it..?
As for this, I doubt anyone here has made one, and even if somebody has, I doubt that person would happen to stumble across this thread and share it with you.

>But i do have a colourbot, but it need the right settings,, maybe any1 can help me out with that? if thats possible
That depends, does it have anything to do with the C++ forum? If not, your in the entirely wrong place.

William Hemsworth 1,339 Posting Virtuoso

I'm not going to encourage cheating, and im certainly not going to give away code, this isn't the sort of thing that can be done in one night, you need to know some advanced C++ stuff, which im guessing you don't know. The only way this is going to get done is if you really put in alot of effort, stopped speaking in l33t sp33k and actually learned C++, that means buying book, reading tutorials and anything you can get your hands on. Personally I don't think you have a chance at succeeding in making this.

Alex Edwards commented: Great answer XD +4
VernonDozier commented: Yes, way too much leet-speak going around. +7
William Hemsworth 1,339 Posting Virtuoso

3 answers at pretty much the same time ^.^ thats a record for me.

William Hemsworth 1,339 Posting Virtuoso

>can you call a function inside that same function
If I understood that correctly then..

If you call a function while your already in it, you have recursion. Take this as an example.

#include <iostream>
using namespace std;

void CountDown(int number) {
   if (number != 0) {
      cout << number << '\n';
      CountDown(--number);
   }
}

int main() {
   CountDown(100);
   cin.ignore();
   return 0;
}

This will keep calling the CountDown function, subtracting 1 from that number, and then displaying it until number reaches 0, when that happends, it will stop calling CountDown and it will break out the loop. Here is a tutorial on recursion - http://www.cprogramming.com/tutorial/lesson16.html

Hope this is what your looking for ;)

William Hemsworth 1,339 Posting Virtuoso

No piece of paper can be folded in half more than seven times, try it ;)

Edit:.. no normal piece of paper can be folded in half more than seven times.
http://www.pomonahistorical.org/12times.htm

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

>Can you complete my code?
No, why should I? We will help, but we won't do it for you, so unless you have a specific problem, im not doing a thing.

William Hemsworth 1,339 Posting Virtuoso

Bill Bryson "A Short History of Nearly Everything", you learn something new on every page :)

William Hemsworth 1,339 Posting Virtuoso

You have given no details at all, you didn't even ask a question or describe a problem :icon_confused: , exactly what do you need help with?

William Hemsworth 1,339 Posting Virtuoso

Yellowcard
The Used
Secondhand Serenade
Dexter Freebish
American Hi Fi
Eagle-Eye Cherry
Jack Johnson
My Chemical Romance
Goldfinger
Mindless Self-Indulgence
Rise Against
Buckcherry
Red Hot Chilli Peppers

- Pretty much in order :icon_cheesygrin:

William Hemsworth 1,339 Posting Virtuoso

You do realise that this is a 6 year old thread, and ALPha hasn't had any acivity on this forum for about 2 years ?.. ;)

William Hemsworth 1,339 Posting Virtuoso

Rounding a number to the nearest whole number is one of the easiest things you can do in C++ :) there isn't even any need for an if/else statement, take this as an example.

float decimal = 3.4f;
int rounded = int(decimal + 0.5f); // 3

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

I have made a few mistakes when programming, probably one of my worst, and I still can't quite remember how I did it, but I flooded the desktop with about 10,000 empty files while making a program that splits one file into many smaller ones. ;) Deleting them was even harder, I had to create a seperate program to delete each one (as you coulden't just select the files you want to delete as the icons went off the side of the monitor) :D

William Hemsworth 1,339 Posting Virtuoso

>Well personally I think its better suited than std::vector
Ignoring that valarray is designed for numeric types, and ignoring that you can't use the majority of operations with valarray on std::string, and ignoring that you've lost nearly all benefits of the standard library by using a ******* child of the standardization process, and ignoring that the standard definition is broken and many implementations of valarray are substandard because nobody cares enough to fix it in light of exression templates, it probably is better suited. But only for your specific example, and only after ignoring numerous rather large turds that you'll end up eating later.

Fair enough :icon_cheesygrin:

William Hemsworth 1,339 Posting Virtuoso

>Don't reinvent the wheel! Use vectors (or safe/auto_ptr) instead of raw pointers if performance isn't an issue.

Unless of course your practicing how to use pointers and arrays, sometimes its better to do things the hard way, and once you know them, take the easier method :)

Alex Edwards commented: Yeah! =) +4
William Hemsworth 1,339 Posting Virtuoso

Well personally I think its better suited than std::vector, and I think its too much trouble to dynamically allocate and delete an array of strings, so I think its a nice solution :]

William Hemsworth 1,339 Posting Virtuoso

How about using std::valarray.

#include <iostream>
#include <valarray>

int main(int argc, char **argv) {
   std::valarray<std::string> arguments(argc);
   for (int i = 0; i < argc; ++i)
      arguments[i] = argv[i];

   return 0;
}
iamthwee commented: i won't use valarrays but your code helped +17
William Hemsworth 1,339 Posting Virtuoso

Well, I would like to say i've become a fairly good programmer and im fully self-taught, but the really trick to it is READING!, you will want to buy yourself a decent C++ book if you want to learn anything fast. You also have to be willing to practice, and not to give up the second you get a problem, and if you get really stuck, you can post the problem here :)

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

>I like what your saying.... to be a good programmer we must love the program..!!
To be a good programmer, you need to know how to make a program.

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

Learn to post properly, firstly why are you bolding and highlighting every post in red, and secondly, use an appropriate thread name.
http://www.catb.org/~esr/faqs/smart-questions.html#bespecific

William Hemsworth 1,339 Posting Virtuoso

Do it yourself..

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

Its pretty much what it says it is, IT Discussion Community for Developers & Technology Enthusiasts. :icon_neutral: If you have a problem, somebody can help you, or you can decide to help people. But there are a lot of forums here, so its hard to sum it all up into "for what is this site".

Alex Edwards commented: =P +4
William Hemsworth 1,339 Posting Virtuoso

I just realised how much of a timewaster this game is ^-^
but.. -1006

William Hemsworth 1,339 Posting Virtuoso

Some of this code is wrong, first of all, the class is missing a semicolon at the end, and you are returning a reference wrong. This is how it should be.

class ThreeD
{
    int x, y, z;
    
    public:
    ThreeD() { x = y = z = 0; }
    ThreeD(int i, int j, int k) { x = i; this->y = j; z = k; }
    
    ThreeD operator +(ThreeD op2);
    ThreeD& operator =(ThreeD op2);
    
    void show();
    
}[B];[/B]

[B]ThreeD &[/B]ThreeD::operator =(ThreeD op2)
{
    x = op2.x;
    y = op2.y;
    z = op2.z; 
    
    return *this;
}
William Hemsworth 1,339 Posting Virtuoso

I tried it, and I found only one very small problem.

#include <iostream>
using namespace std;

const int N = 20;

int main()
{
   int a[N], i, nb, tmp;

   for (i = 0; i < N; i++) {
      cout << "Please enter an integer: ";
      cin >> a[i];
   }
   do {
      nb = 0;
      for (i = 0; i < N [B]- 1[/B]; i++) {
         if (a[i] > a[i - 1]) {
            tmp = a[i];
            a[i] = a[i - 1];
            a[i - 1] = tmp;
            nb++;
         }
      }
   } while (nb != 0);

   cout << "The sorted array:" << endl;

   for (i = 0; i < N; i++) {
      cout << "iIntegers[" << i << "] = " << a[i] << endl;
   }

   cin.ignore();
   cin.ignore();

   return 0;
}

Delete the part highlighted in red, as this is skipping one of the integers in the array.

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

Don't kill me for this (I know this must be the worst idea ever), but WOOH! I figured it out! :D

#include <iostream>
using namespace std;

void addNodes(string names[])
{
   bool exception = false;
   size_t length = 0;
   string temp;
   do {
      try {
         temp = names[length];
         ++length;
      } catch (...) {
         exception = true;
      }
   } while (!exception);

   // No idea why, but you have to take away 3
   cout << (length - 3);
}

int main() {
   string names[10];

   addNodes(names);

   cin.ignore();
   return 0;
}

edit: but I just realised this doesn't even work if you dynamically allocate the names.. darn

William Hemsworth 1,339 Posting Virtuoso

Read this before posting.. see if you can figure out what you did wrong, all by yourself :icon_wink:
http://www.daniweb.com/forums/thread78223.html

William Hemsworth 1,339 Posting Virtuoso

Would you mind giving some more information, perhaps show some code that may be causing the problem or an error message, we can't just "know" what the problem is :icon_cheesygrin:

William Hemsworth 1,339 Posting Virtuoso

You just posted in a 4 year old thread, read THIS before posting again, incase you missed it..

William Hemsworth 1,339 Posting Virtuoso

Hmm, im not sure if this is exactly what you need, but perhaps you should take a look at WM_ERASEBKGND, it is this message which automatically erases your background when resizing or doing some sort of activity with your window, by doing this manually, you should be able to remove the gray flash.

Hope this helps :)

William Hemsworth 1,339 Posting Virtuoso

Nope, the preprocessor ONLY works before compile time, remember that, so you cant have a mix of the two :)

edit: but maby you should look at the typeid operator, it might be what you need for that example.

William Hemsworth 1,339 Posting Virtuoso

I am sorry, I don't actually see the 'Japanese' part of the humor; what I see is a stupid white guy who can't understand symbolic languages. Would you please explain the 'Crazy Japanese' part?

Gee pal, whats your problem?? Its not the "Japanese" thats funny, its whats on the page..