twomers 408 Posting Virtuoso

One problem. scanf("%d",&kilowatt); kilowatt isn't an integer. Change the format specifier to what you'd use for a float.

Is this right? (kilowatt-15)*20+(10)+compute_tax(total); Haven't looked at it, just seems odd that you're taking 15 from kW.

Is this right? totalwtax=total+tax; Should it be * not +?

twomers 408 Posting Virtuoso

Here's a very crude example which I haven't tested, but even if it doesn't work it'll show you how to go about the problem...

struct mylist {
  int num;
  mylist *next;
};

int main( void ) {
  // Setup list
  mylist *l = new mylist;;
  l->num = 42;
  l->next = new mylist;

  l->next->num = 24;
  l->next->next = NULL;

  // Print which is bigger
  mylist *iter;
  for ( iter=l; iter->next && iter!=NULL; iter=iter->next ) {
    if ( iter->num > iter->next->num )
      std::cout<< iter->num << ">" << iter->next->num << "\n";
  }

  // Delete list
  iter = l;
  do {
    l = iter->next;
    delete iter;
  } while ( iter = l->next );
}
twomers 408 Posting Virtuoso

Maybe something like:

nodo *p1, *p2;

p1 = List;
p2 = List->next;

if ( p1->key == p2->key ) // or p1->key == p1->next->key
 // do this...

Your problem is that you don't have a random access element for your list, i.e. the [] operator. You could probably write that if you wanted.

twomers 408 Posting Virtuoso

Actually my fingers method is pretty stupid. Kinda rules out anonymous ballots if your prints are recorded :/

Dave Sinkula commented: I had completely missed that angle, concerned instead with a limited number of lifetime votes. +17
twomers 408 Posting Virtuoso

Doesn't hang for me. What OS and compiler are you using?

twomers 408 Posting Virtuoso

Fingers. If you want to vote for someone you cut off your finger and put it in a box. Most fingers wins. It'll mean only people who REALLY want a candidate will vote so you get the best government.

twomers 408 Posting Virtuoso

Try, at least. Then come back with an attempt and we'll help from there. We'll explain your mistakes, suggest how to fix and then you'll have a working solution.

twomers 408 Posting Virtuoso

In my opinion without some careful management it's asking for trouble. Why do you have to open it? Couldn't you do something like...

std::[i/o]fstream fstr;

// ...

fstr.open( "file_name" );
do_recurs_function( fstr, /*other params*? );
fstr.close();

I had a similar situation where I was opening and closing streams (to different files though), in a large loop. I decided to forget opening and closing and just open once and close once and it sped the program up hugely. I honestly can't remember the speed performance improvement but I marked it as significant.

Edit - Note: in passing file streams into functions you have to pass by reference (or pointer I think). Can't pass by value.

#include <fstream>
void fstream_function( std::ifstream &in ) {}

int main() {
  std::ifstream in;
  fstream_function(in);
  return 0;
}
twomers 408 Posting Virtuoso

This is more of a "Here's my problem. I've tried this but it doesn't work, please help" site rather than a "be my friend and fix my problem site". Explain the problem here and you'll likely get a response.

twomers 408 Posting Virtuoso

To understand the reasoning of this execute the following:

int main() {
  std::cout<< sizeof( unsigned long) << ", " << sizeof( unsigned short ) ;

  return 0;
}

Basically short*short = short, but you're comparing this to a long. So there's a size mismatch. YOu could cast the shorts if you want to get rid of the warning or use only longs or shorts.

twomers 408 Posting Virtuoso

Heh. In between. Normally people say 'from'. I was going to ask you what system you're using but this solution, I think, covers most of 'em.

twomers 408 Posting Virtuoso

>> I have a fixed packet length
I thought the length was a parameter of the packet... guess not anymore.

>> But you could use malloc() to dynamically create an array of any size right ?
Course. It's no different to any other dynamic memory allocation program. Consider this simple exmple (from cplusplus.com):

/* malloc example: string generator*/
#include <stdio.h>
#include <stdlib.h>

int main ()
{
  int i,n;
  char * buffer;

  printf ("How long do you want the string? ");
  scanf ("%d", &i);

  buffer = (char*) malloc (i+1);
  if (buffer==NULL) exit (1);

  for (n=0; n<i; n++)
    buffer[n]=rand()%26+'a';
  buffer[i]='\0';

  printf ("Random string: %s\n",buffer);
  free (buffer);

  return 0;
}

If you were to modify that slightly to something like:

#include <stdio.h>
#include <stdlib.h>

int main ()
{
  /* Record all packets via this variable, then save it via 
     malloc to a memory location that's the right size */
  char packet_buffer[MAX_PACKET_SIZE];
  char *packet;
  int packet_length;

  /* I'm assuming you have a function like thse */
  read_in_packet( &packet_buffer );
  packet_length = get_packet_length( &packet_buffer );

  packet= (char*) malloc (packet_length+1);
  if (packet==NULL) exit (1);

  memcpy( packet, packet_buffer, packet_length );

  free ( packet );

  return 0;
}

I haven't tested the above code so it mightn't work. Now, what you could do is simply save the recorded packets to a file. But what would be neat would be to make packet a char **, and dynamically allocate a 2d array of memory, one dimension for the current packet, and the …

twomers 408 Posting Virtuoso

Yeah. Linked list might be of use. So you can continuously grab packets without worrying too much about where they go. Have you the dynamic size thing working? That the length parameter determines the size of the packet?

twomers 408 Posting Virtuoso

I'd use the modulus operator and the division operator in a loop, something like:

do {
  knum += num%10;
} while ( num/=10 );
twomers 408 Posting Virtuoso

>> I didn´t know that there was 2 arguments
There's one way to find out, use a reference. www.cplusplus.com is a good one, IMO. Here's vector's constructor: http://www.cplusplus.com/reference/stl/vector/vector.html and at the bottom there are examples.

twomers 408 Posting Virtuoso
#include <iostream>
#include <vector> 


int main( void ) {
  // 4x5 (4 in x, 5 in y) array, containing -1
  std::vector< std::vector<int> > vvint( 5, std::vector<int>( 4, -1 ) );

  for( int j=0; j<vvint.size(); j++ ) {
    for ( int i=0; i<vvint.at(0).size(); i++ ) {
      std::cout<< vvint[j][i] << " ";
    }
    std::cout<< "\n";
  }

  return 0;
}

Edit: Beaten to it. Forgot to post.

twomers 408 Posting Virtuoso

The first thing you should read about is dynamic memory allocation in C. malloc is the function you're gonna be looking for (and free afterwards). When you understand this write a simple program that does something like this:

  1. Prompt the user for a number.
  2. Dynamically allocate an array of this size.
  3. Copy some 'dud' information into this.
  4. Free the array.

This is basically what you need to do. I still recommend creating your own structure, but that's just me. That way it's easier to get specific information... saves you having to #define the length location etc. You can just use something like packet.length. Anyway, after you've written that program integrate it into the other code.

twomers 408 Posting Virtuoso

>> Interesting, a dark rap!
Where? Has it been observed? Wow!

twomers 408 Posting Virtuoso

I think you have all your numbers mixed up... you're scanning d, a is used as the while loop control, c has 2 being subtracted from it, and then you're printing a. You only need one variable. So instead read in a, use a cor while( a>0 ), say a -= 2;, and finally print a.

twomers 408 Posting Virtuoso

>> I was going to put this in my geek thread but since it is really about dark matter, well - here is a geek rap about looking for dark matter.
That made me cringe, but like a car crash, I couldn't stop watching it.

>> "God's Matter and God's Energy"
Not until it's proved.

twomers 408 Posting Virtuoso

I did something similar to this before and I found the best way to do it was to create a packet structure... something like:

struct packet_structure {
  char preamble;
  char length;
  char from;
  char to;
  // ... etc
};

I found it a lot more accessable that way. Do you have to have it as an array? It's a little less... nice to manage that way.

What're you having trouble with? Getting the length? Or using the length in defining the length of the big array and then combining everything into this?

twomers 408 Posting Virtuoso

So a number is taken from a user, and 2 is subtracted from it until it's 0? Why do you have an array or a[100]? Do you need to save each number? Just try to think about it.

Problem:

  1. You're given a number.
  2. You take two from this number,
  3. you print it,
  4. you check that it's above 0
  5. and repeat.

Solution:

  1. Done!
  2. Change to c-=2;
  3. To do (put a printf in the while loop)
  4. I think the >= should simply be a > in the while loop.
  5. done.

>> I have to do this without using my c said sir
I think the aforementioned 'sir' might appreciate that.

twomers 408 Posting Virtuoso

I don't run linux so I don't know if this'll work, but here's a solution I've found that'll work on linux: http://www.linuxquestions.org/questions/programming-9/restricting-multiple-instance-of-a-program-242069/? It uses a lock file but the lock is killed when the program ends, even if killed or crashed etc. What you do is have an #ifdef switch. Check for a windows maching, and if it's true use the code I first linked to above. Then #elif for a linux machine and paste the code from this link... i.e.

#ifdev WIN32
// windows code

#elif <whatever else>
// linux code

#endif
twomers 408 Posting Virtuoso

Eh... that's dangerous enough. What happens if the program crashes for some reason? I think the solution I posted from msdn is better in regard to that, though not portable. Make a header file, make an instance of the object, and test the return value of the "IsAnotherInstanceRunning" method.

twomers 408 Posting Virtuoso

What time do you want it on your desk for?

I've never had to do this, but did a quick Google search and got this -- http://support.microsoft.com/kb/243953 Looks about right, works too.

twomers 408 Posting Virtuoso

So I have a banning within the hour at ... 9:1. Do us proud.

twomers 408 Posting Virtuoso

But how can I pass out when there's a challenge to be met? Talk about ethics!

twomers 408 Posting Virtuoso

In this order (ordered by difficulty of problem to be tackled) -- do nothing out of ordinary, music, tea, coffee, beer, Irish coffee, straight whiskey. Normally do a linear iteration through the set and stop when the relaxing method meets the challenge.

twomers 408 Posting Virtuoso

I dunno... babies sleep for like 12 hours a day. My nephew's like 1 sleeps from 8PM to 7AM with a nap for an hour or so.

twomers 408 Posting Virtuoso

So it'll say like 13 and you want to grab the next 13 characters? Will the length actually be wrapped in []? If ya have boost installed use boost::regex for the simplest way. You might be able to use strtok to split them all with respect to [, skip till ] and grab the rest of the string. If [ and ] mark the size of the string you don't actually need the length.

twomers 408 Posting Virtuoso

English, C and Babel (as in the fish).

twomers 408 Posting Virtuoso

I had an amusing one today. I'm writing a SMS sending program. It's a remake of a program I wrote ages ago for the same purpose, but the wobsite to which the program interfaces changed its layout so I had to change my program. Anyhow, cookies are now used by the site to store the numbers of the recipients and the website automatically deletes them after it has finished sending the message... but, of course, I forgot to... so the text messages that were sent went to everyone to whom a text was sent for the duration of the session... increasing exponentially (WRT new recipients). I didn't notice this and gave the program to some friends of mine. Definitely worth it. I was tempted to leave it in and not tell anyone :)

twomers 408 Posting Virtuoso

I like this topic. Wasn't it Einstein who said "You don't understand something fully unless you can explain it to your grandparents"? I'm nearly sure I'm mixing quotes, but I stand by it.

twomers 408 Posting Virtuoso

Why do you say "G-d"?

twomers 408 Posting Virtuoso

Kind of a thread mix, but I was re-reading Hitchikers again and came across this: "Anyone who is capable of getting themselves made President should on no account be allowed to do the job."

twomers 408 Posting Virtuoso

>> then perhaps all the killings of one another "in god's name" will end.
Just because some people of some religions have an idea that killing "in god's name" is permissible doesn't mean they all do. Sure, most have done in the past. But don't slam them all with an extreme stereotype that is today only linked to the select few. And don't talk about history. That's what it is - history. It shouldn't be accepted or acceptable either now or then. Bad things happened, but not only religious cullings. You don't need a list. None of it should have happened, but it did. We in our high chairs of hindsight point the finger and say "that was bad. That shouldn't have happened". But you know what? I bet if we were there nothing would have changed (be it religious killings or plantations). No matter what you say people follow the crowd. I found your sample message board amusing. I didn't know you were that old!

twomers 408 Posting Virtuoso

117.67. Don't think it's a very good test. What it measures what you have watched. What you've read. What you've seen. etc. What does toy story say about how smart you are? In my opinion an IQ test should give you something (a picture, piece of text, etc), and ask you questions on it. Further knowledge shouldn't be required. An IQ test should measure reasoning, understanding, linking. I've done online tests and have scored anywhere from 117.67 to 154 or something. In that IQ test you either knew the answer or you didn't. There was no way to work it out.

Hehe. Apparently I'm daniweb's #1, Ireland's #1, world #479, Dublin's #1 (I don't live in Dublin). http://www.iqleague.com/user/GsWZBgKWeU-r8pqmAGdx1w "Calculated on 5/24/2008 6:18:16 AM based on last 10 questions. Estimated base IQ score is 127.81. There was penalty of 10.14 for answering only 10 questions." Pff. I also disagree with timelines for IQ tests. Or at least for timed IQ tests. There should of course be a time limit, but nothing too short.

scru commented: you forgot your rant tags +3
twomers 408 Posting Virtuoso

I believe you misinterpret the meaning of strawman arguments. He was talking about using physical evidence and experiments (or so I gathered), to prove/disprove the existance of God. A strawman makes an imitation of the subject which is significantly lacking in similarity, calls on a trait of that object and degrades the virtue of the former by slandering the latter.

twomers 408 Posting Virtuoso

>> look up straw arguments
Eh. Not sure what that has to do with things.

twomers 408 Posting Virtuoso

The article was very specific, jwenting.

twomers 408 Posting Virtuoso

I read somewhere that regular expressions don't work on people, vegaseat...

twomers 408 Posting Virtuoso

Alpha and omega. Beginning and end.

All I can say is thank Dani for the webpage preview. Saved a lot of time!

twomers 408 Posting Virtuoso

Do it via a timer. In the message loop handle the timer event for repainting and repaint.

twomers 408 Posting Virtuoso

Probably a good idea.

twomers 408 Posting Virtuoso
//#include <fstream>
twomers 408 Posting Virtuoso

This is an interesting discussion alright. Some of the views here I agree with, some I have to think about, but the funny thing is that it doesn't really matter. If God made the universe he might have done it via evolution or by the ways discussed in the Bible, or they may be one in the same (could people have understood what it was in the OT days?). What's important in that line of thought is that God did it, and no matter the way it was achieved it was an impressive bit of work.

If God didn't create everything then the universe just came to be some time in the past. Unless you're a physicist who is trying to figure out what happened in the first few attoseconds of the universe and feel the need to build a LHC of your own and model it I don't think you should loose sleep.

twomers 408 Posting Virtuoso

>> Peace on earth for 24 hours. Very unlikely though!
Practising for Ms. World there, Ene?

twomers 408 Posting Virtuoso

Try using regex in a program and tell us what happens!

You'll need a regex library. There should be some freely available. Boost has one, right?

twomers 408 Posting Virtuoso

You could always have them in an array and use min_element and max_element
From site:

// min_element/max_element
#include <iostream>
#include <algorithm>
using namespace std;

// snip

int main () {
  int myints[] = {3,7,2,5,6,4,9};

  // using default comparison:
  cout << "The smallest element is " << *min_element(myints,myints+7) << endl;
  cout << "The largest element is " << *max_element(myints,myints+7) << endl;

  // Snip

  return 0;
}
twomers 408 Posting Virtuoso

I'd say 24 season one. The others were a bit too much for one man to handle in one day. But season one was good. Perfect day.