WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

...can be divided by both 2 and 7

Ahhh, so I did misread. Sorry.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Easiest is to pass in the position of the last move then check each direction from that location for 3 in a row.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I'm Queen. I can say Whallah if I want to :-P

Yes, ma'am :o

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Really? . . . http://eternallyconfuzzled.com/arts/jsw_art_rand.aspx

Either way works, and some would recommend the OP's way over yours (myself included).

Thanks for the link. Interesting.... I'm convinced

I also noticed an error in my solution. So go ahead and use your original equation. :o

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

And what's our incentive to read 320 lines which inlcudes "Extra shit load added for crappy fun"? Maybe you should post the section you are having trouble with...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

It doesn't appear so. I there there was a FORECOLOR property but there isn't -- at least not for buttons. Weird. Leave it to M$ to forget a useful property.

I did find this solution doing a Google search for vb "command button" color. Maybe you'll find other options.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Thanks again,
but this dont work ,when im tryiing to open the file i get my error message
If (fp==NULL)
printf("ërror");


is it working for you?

Then you're doing something wrong. I think it's on line 10... :confused:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Can I move it too? :twisted:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Just try to answer the question only the question, any u will become smart.

This is a public forum. Anyone is free to post whatever he wants as long as the reply doesn't violate any of the forum rules. If you don't like something, you are free to move on.

Agreed. Don't get snippy with ~s.o.s~. He asked a legitimate question about your project. And speak English. "any u will become smart" is not understandable by us that know the language. Could "any u" be "and you"? If so, how is answering your question going to make him smart? Logically unsound reasoning... ;)

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I am having troubles getting this program to generate random numbers. Right now i have it set up to only generate 1 and 19. I do not know how to generate random numbers.

thank you if anyone can help my dumbass.

change a = lowest+int(range*rand()/(RAND_MAX + 1.0)); to a = (rand() % highest) + lowest; This takes the random value, divides it by highest and keeps the remainder (0-18) then adds 1 (0-19)

Now you're a smartass :mrgreen:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

As mentioned, use getline() to read the input. Test the first character and if it's '\n', only a RETURN was entered. Otherwise process the line 'cuz something useful (hopefully) was entered.

That won't work with getline() because getline() trims the '\n'. The first character would be '\0' in a C string and s.empty() would be true for a C++ string.

Sorry 'bout that. I thought getline() was just a wrapped fgets() . Ya larn sumtin' new ever' day, eh? :mrgreen:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
/* You really shouldn't use goto's they're gay but what-the-hell */
    End:

"Practice what you preach."
If you
1) know you shouldn't use them,
2) then say you shouldn't use them,
3) and do it anyway,
what are you teaching the people that are new to the language? It's confusing because for them, the code is now useless. They don't understand enough to know what to ignore and what is good... FYI... ;)

John A commented: Good points... +6
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

fscanf() does not differentiate between rows. So you will be better off not using that function at all. Instead, I would use fgets() to read one row at a time then parse the string that was read.

char line[80];
char *ptr = 0;
int i = 0;

while( fgets(line, sizeof(line), f) != NULL)
{
   // clear the array
   memset(v,0,sizeof(v));
   i = 0;
   // extract numbers from line string
   ptr = strtok(line," ");
   while( ptr != NULL)
   {
       // insert into array
       v[i] = atoi(ptr);
      ++i;
      // get next number from the string
      ptr = strtok(NULL, " ");
    }
    // now do something with these numbers

}

From a purely style issue, I would not use memset() nor strtok() . memset() is not necessary because you should be using only the array values you've loaded so you shouldn't have problems with uninitialized variables. As for strtok() I prefer to parse the values by hand with loops. For example:

do
{
    fgets(line, sizeof(line), f) != NULL)
    n = 0;
    // skip leading whitespace
    while (isspace(line[n])) n++;

    i = 0;
    do
    {
        // extract numbers from line string
        v[i] = atoi(&line[n]);

        // skip to next value
        while (!isspace(line[n])) n++;  // skip over this value
        while ( isspace(line[n])) 
        {
            if (line[n] == '\n')  break;  // isspace() sees \n as whitespace
            n++;  // skip over the spaces
        }
    } while( line[n] != '\n')

I feel I have more control over the input by doing essentially what strtok() does anyway. As I said, purely a …

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

grain

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

First sign of senility is... is... what were we talking about?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

being old is

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

"You yourself hired me, ma'am. I have been your nurse these 3 years come May," smiled Nurse Diesel, used to the memory lapses of her lady.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

If you want a haskell section, submit a code snippet with 'haskell' as the syntax language and whallah ... a haskell section :)

FYI, it's voila! It's French ;)
Wallah isn't quite right...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

thanks for the reply, seems like you're always helping me out. what do you mean when you say that my post was kind of strange? What I did was copied my code from the compiler then pasted it. The only thing I did was space things out a bit, because you told me once before that my formatting looked bad and that I should space things out.

Interesting. Your post had a color tags on every line of the code. I wonder if your IDE copies the color.... Nyah, that doesn't make sense...

Your spacing is good. Your intenting needs a little work, and make more use of {} and () ;)

Also I should use and since I'm checking that the integer I entered was divisible by both 2 and 7, correct?

That's what the IF I posted does.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

So what's the problem? You should describe what's wrong so we know what were looking for.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

im learning assembley next year btw. Is it hard?

Not really. You just have to move every value from memory into registers to work on, then back to memory when dealing with variables. You'll end up writing more lines of code to do simple things, but knowing assembly gives you a greater appreciation for what's really going on in the computer.

So if i wanted to learn about how to make operating systems, should i learn about computer sciecne or computer programming???

Check with the curriculum at the school to see if they teach OS design. It's not simple, and they might not offer a course in it. But a class or two might touch on it, at least.

You will need to know a little assembly. Device drivers are often written in it (so I hear).

More and more are actually written in C I believe. Because C is close to assembly, it has made many inroads into what used to be assembler-only code. But it has not vanquished the big A by any means.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Is there really anything wrong with learning VisualBasic?

NO.

That is really the only reason i want to learn a language like c, c++, c#. So many people have told me that vb is "too sissy".

They need to grow up.

Personally i love VB. The code is easy to understand (coming from a BASIC background), and i caught on fairly fast. The only problem is that i have been "picked on" about VB, so i decided to see what all the hub bub is about...

I've been programming probably longer than you've been alive, long before C, C++, and VB even existed. For doing GUI programming, VB is quite good. You can build pretty robust applications and fairly quickly. C/C++ is better for commercial applications, but for in-house and personal apps, VB works quite well.

Don't let others try to make you feel bad because of VB. They are programming snobs. VB is just not the "in" thing anymore, but it's still alive and kicking...

Ravalon commented: Let there be approval ^_^ -Raye +1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Hey again, I was hoping someone here could look at my code and tell me why I'm not receiving the correct output.

Here's what I'm supposed to do:Write a program that asks a user to enter an integer, say n,then list all the numbers that are less than or equal to n and can be divided by both 2 and 7

When I run the program it will show all the numbers less than the integer I entered. However when it comes to finding out if the number is divisible by 2 and 7, no matter what number I enter it says it's divisible by 2 and 7.

If someone could show me what I'm doing wrong i'd appreciate it.

Sure. First I have a question. Did you do something other than type around your code? The post was kinda strange and I'm wondering if you did something different?

#include<iostream>
using namespace std;

int main()
{

   int n;

   cout << "Please enter an integer: " << endl;
   cin>>n;

   for( int i = 0; i <=  n; i++ ) //// you need braces around all the code
                                  //// you want in the FOR loop.
   cout << i << endl;

   if( n/2 && n/7 )    ////This will rarely work.  See below
                       //// Use braces here, also.... 
       cout << "The integer you entered is divisible by 2 and 7" <<endl;

   else

       cout << "The integer you entered is not divisible" << endl;

   return 0;
}

The fix:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

As mentioned, use getline() to read the input. Test the first character and if it's '\n', only a RETURN was entered. Otherwise process the line 'cuz something useful (hopefully) was entered.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I been trying to work on my indentation and I thought I was getting better

Here's a tutorial about code formatting. Concentrate on whitespace as well as indentation. A differnt IDE won't do it all for you, and knowing how to format is extremely important.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

but i though the entry in fopen has to be a either in "" or predefined?

Why would you think that? ;)

well i used

fout = fopen("%s.txt", "w");

but when i leave it as (filename,'w') and compile and run, the program notes a windows error and closes, and no file is generated

Why did you change "w" to 'w'? Change it back and it will work.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You still have to open the file for writing. It doesn't magically get created just because you create a name in a variable...

Look up fopen()

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I'm confused by your question.

Currently the list of "New Posts" and "Today's Posts" are listed in chronological order. It would be easier to find posts we are interested in if the sort order instead was
MAIN GROUP (software dev, web dev, etc) then
FORUM then
TIME

for a 3-field sort order

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

the program runs, but no output file is generated? am i missing a command still?

#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(int argc, char *argv[]) {
char line[255];
fgets(line, 255, stdin);
char filename[80];      // This line can't be here.  It has to 
                        // be above all executable code in C
sprintf(filename,"%s.txt",line);
  return 0;
}

Yeah. Where do you:
1) open the file after you generate the name?
2) write to the file?
3) close the file before exiting?
:?:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Fortran is showing its age. Today its only really used in mainframes

Why do people that don't know what they are talking about insist on saying it anyway?
http://inventors.about.com/library/weekly/aa072198.htm
http://archive.adaic.com/docs/reports/lawlis/n.htm
http://www.thocp.net/software/languages/fortran.htm

Key phrase: "still widely used today." And if that's not enough, here's up-to-date info about a language that's "past it's prime" ;)

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

the code works totally fine now!

Great!!!

if i type the strings too long the program crashes.

Is this a different definition of "totally fine" that I'm not aware of? ;)

I already explained why here

I need to free up the memory using delete[] but i still dont know where to use it.

Where in the program are you done with the buffers you allocated? That's where you have to delete all the buffers...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Because in such a trivial program it doesn't make a hill of beams which way its coded. Creating another process is also trivial in most of today's computers; the os would barely even know the process is present in the system.

All this is true, but aren't we forgetting that we should me modelling standard practices, so we don't have to retrain them 2 weeks later?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I think this is a great idea, but 3 pages of new posts, most of which I'm not interested in perusing at the moment makes it somewhat unwieldly. If they can be sorted by FORUM-INDEX + FORUM + TIME it might be easier to use since I for one go to the C++ forum 1st, then the rest of SoftwareDev. At least what we're interested in would be grouped together.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

If you can terminate input into the array by using some other approach, that is, if using Ctrl-z isn't an instructor/employer imposed requirement, then I would encourage you to do so.

Yeah, I was going to mention that, too, but forgot. Simply read your line and if there is only a newline in the buffer, assume they didn't want to input anything and start processing...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Contact your local library or unemployment office. They have books that outline salary ranges for most if not all professions.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

yeah, its unlikely c++ wll be around for another 20 off years

Really? Basic, Cobol, and ForTran are still around. And C++ is only 30-40 years younger. So don't bet on it...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Also, this piece of code has a BIG problem:

for (int i = 0; i < 10 && z(); i++)
    {    
        char* temp = new char;//[500];
        cin.getline(temp, 500);

How large is the area pointed to by temp? I'm surprised it didn't crash on you yet.

I was also thinking about using the cin.eof() function because it seems a lot easier than a boolean. i believe when ctrl+z is entered, it recognizes it as the end of the file and should run the program. I know that it should look something like this:

if(cin.eof())
{
cout << "done!"
exit(0);
}

but I am not sure where I need to implement this in my program.

Maybe where you ask for the input?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

does a sunwalk

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Did you realize you can't just write any ol' sentence?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

stoke

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Only problem with that is that it requires VB.NET... Good ole' VB6 doesn't have an opacity setting on the forms.

- Sen

Sorry. My psychic powers weren't tuned in, I guess ;)

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Not to mention Bliss and a host of other languages...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Do you know what arrays are?
Do you know the if statement?
Do you know the for statement?
Post your code after reading this and we can help.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Also, look at Joe's suggestion about the array. It will make your code extremely simple.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

And that's when Revlak entered the picture, riding his flame-gold stallion. Tall, rugged, with deep green eyes, eons ago he would have been a god. "May I be of service, M'Lady?"

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

If you don't want to be bogged down with M$, go with C or C++. They are more general and not 'controlled' by M$

Nor is C#. Both C# and CLI are internationally standardized. It's not Microsoft's fault that nobody has yet written an implementation that rivals .NET and Visual C#, is it? ;)

If M$ has no rivals yet, isn't M$ still in control? I stand by my statement. ;)

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

This might work...

Set the form to transparent background and maximize the window.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

If you don't want to be bogged down with M$, go with C or C++. They are more general and not 'controlled' by M$

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

makes you ill