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

I assume you don't care about "the compiler under the hood" but how the compiler is used/interfaced.

I personally prefer Borland 5.5. Grew up on the command line so I get to use my editor of choice (VEdit) rather than learn the editor they choose for me.

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

There are other problems..
"Generate 100x4 unique arrays" even rand() won't exactly be rand() if you have a fast enough machine..

What's this supposed to mean? Random has nothing to do with the speed of your machine...

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

Hey All i am making a connect four game. I have done most of the code but need help in some bits

1) Which is how to code to see if there a win from vertical, horizontal or diagonal. - The Grid is 7 by 7. - I no idea how to code this and if i need in a function on its own or in the main game loop, also do i need make one for both p1 and p2? or will one just do??

As vishesh suggests, a 7x7 array would work great. You can define the board to be int board[7][7]; .
Then for every move (say board[2][3] for 3rd row, 4th col) you look at all the locations that could make up a win.

The more functions you create, the better (within reason)

2) After someone wins I want be able to score the result of both p1 and p2 (win lost or a draw) into a notepad file. I also want make a function to get that notepad to bubble sort all the top 20 players and show them in ranking order. Also is there a way of getting the notepad file not to allow ppl to edit the scores without playing the game??

Open the score file in append mode. Output the new score, close the file. This will give you a list of all the games which you can process when you output the scores.

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

Walt p - u can add in 2 letters not 3 :)

Rules were changed. :p Dartsale? :confused:

Farmsale

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

Properly prepared, flank steak is quite good.

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

yardsale

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

hairy mole on

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

Last for me was Conan! On the big screen, too! Great movie.

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

of human events

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

And let's not forget Aunt -- a from cat or bar?

And the last letter of the alphabet -- zee or zed?

Then there was the Datsun -- Dat rhymes with bat or cot?

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

I think you've just run into one of the reasons us old-time programmers despise the addition of SPACE as a valid filename character -- even M$ can't figure out how to consistently handle the character. You may be out of luck.

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

RaCheer. please consider formatting your code better. You really need to indent so the code can be followed.

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

well i thnk ths will solve ur prob...................

If you are going to do people's homework for them, at least give them good code in a well formatted style.

Better yet, let them write the code and you suggest options so they can learn to do it themselves...

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

Then can we revert back to the actual time until you find a different solution?

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

:eek:I still cant understand. can you sate a sample pls? thanx..

Hmmmm, looks like you're tryin to run and you can't walk yet...

i am just a beginner and using c++ just 3 days ago. i hope you understand.. thanks..

Yep, I understand. As Sir Dragon said, this task seems to be beyond your capabilities. You don't seem to have the basics of looking at a string and figuring out what's in it yet. Back up to previous lessons and get to know strings.

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

Look at the first character
If it's a digit, call a function that converts the next values up to the comma into a number. Return the next location (pointer or index) in the string just after the comma

If it's a ", call a function that moves everything up to the next " into a character buffer. Return the next location (pointer or index) in the string just after the comma

repeat the above two texts until you run out of characters for the line.

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

Instead of this

if(n<=0)
    {return 1;}
  else
    primeTest(n);
  return 0;

do this:

if (n > 0)
{
    primeTest(n);
}
return 0;

It's simple and easy to read.

And:

for (int counter=1; counter<=n; counter++)

A for loop will not give you n primes, it will simply test the values 1 thru n for prime. Use a while loop instead.

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

Hasn't anyone mentioned code formatting yet? You need to indent your code so we can follow it.

And your titles need work -- see this. Any more lame titles also warrants an infraction.

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

Since your code looks correct the only thing I can think is that the OS you are on is forcing the 8.3 filename convention.

Not likely since VB only works on $M Operating systems which don't have 8.3 limitations.

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

In other words, every time you output a value, add 1 to a counter. When it reaches you 'magic number' exit the loop.

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

I tried spacing stuff out and lining things up ...

Does look better. Read this tutorial for more information.

... but really didn't add many brackets because they've been a sore spot with me.

That's like saying "I want to be a writer, but punctuation confuses me so I won't use much." Simply put brackets around every statement that could be a compound statement. ( if , for , while , etc.)

Any suggestions you (or anyone else) have further regarding the formatting are welcome and appreciated. Thanks again everyone.

Look at good code. Check out the code from poster's here that have a high post count. See what they do and compare it to the tutorial above.

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

Read the first post in this thread.

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

Thanks a lot. It's reading the file just fine now but I noticed another problem after running through a couple generations. I neglected to include a command to populate a cell with three neighbors. No kids means everyone just slowly dies out. Here's the relevant code (let me know if you need more):

I don't think I understand. What does this code do?

if (neighborcount == 2)             // 2 neighbors 
    tempWorld[i][j] = World[i][j];  // stays alive.
      else if (neighborcount == 3)        
    tempWorld[i][j] = true;         // 3 neighbors:
                                        // stays alive

      else tempWorld[i][j] = false;      // 1 and 4+ neighbors:

Doesn't it test for 3 neighbors?

And please format your code better -- it's a little hard to follow. You need more {}'s and proper indentation to make it easier to read.

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

where does the sprintf() go i have never used that or seen that before I am new and just learning the ropes.

Since you're using C++, might as well stick with setw And hasn't anyone mentioned code formatting yet? You need to indent your code so we can follow it.

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

But then again, maybe I am blowing smoke in the wind.

Yeah, it's somewhat smoky in here... :D

what compiler are you using? I tried to compile it with three diffeent compilers and none of them knew about strptime().

It seems to be the reverse of strftime() in *nix strftime() does not normalize the data in the buffer. You have 60, it prints 60.

Since you put time_t t = mktime(&tm); in the code and never use it, I assume you wanted to reconvert the calendar time into the tm structure again.

This technique didn't work for me, though. mktime() returned an invalid time. Be sure you check it before proceeding.

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

You know, a quick google search shows so many illustrations and explanations it's incredible!

Some flowcharts you can look at:
Number 1
Number 2
Number 3

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

Dani, now that you're back, could you please make some comment on this? There seems to be support for adding the actual TOD to the post time, but we have no idea whether you agree or disagree. You've been so silent. I'd like to at least know if it's a possibility or not.

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

>my problem is, that i have been trying to use a counter to display the average and im stumped
The problem is that you need to store the data in some sort of array -- preferably a vector, and then you can calculate the average.

Why? Go simple.
In this loop:

while (inFile) //End-ofFile Controlled Loop
{
    outFile << "\t" << ref << "\t" << mydate << "\t" << Celsius(ctemp)
            << "°F" << endl << endl; // Write Record
    inFile >> ref >> mydate >> ctemp; // Read File
}

Simply add ctemp to a total counter and add 1 to a 'lines read' counter before your output. Then when you exit the loop, calculate total/lines. No need to store all the data unless you need it later in the program.

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

Yes

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

i don't want to read any input...the console window doesn't close....Just the output that appears is wrong...

The program that i posted simply reports the size of file..it doesn't need any interaction from the console....

Oh? That's not what the other post said. We were answering this problem:

When i try to run the executable through visual studio {pressign ctrl+F5} it does nothing{although the test.txt has size of 1kb}, when i run the exe through the command prompt the program works fine...

"it does nothing" is not the same as "output that appears is wrong"

Therefore, start over and describe the problem in detail.

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

Looks like someone hijacked a thread and forgot to read the Rules

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

hi, i have this simple code, that compiles on visual studio 2005.When i try to run the executable through visual studio {pressign ctrl+F5} it does nothing{although the test.txt has size of 1kb}, when i run the exe through the command prompt the program works fine...

Does anyone know why this is happening??

The program opens a window, runs very quickly, finishes, then closes the window. Add cin.getline() just before the return

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

Heh, I have seen that before...yeah Google Groups... :D

Nope, I wrote my own self. :mrgreen:

what the heack this hole thred didnt eaven make sence to me????????

You know, if you have nothing useful or interesting to add, you aren't required to post.... ;) Lots of your posts recently have been obviously just for the sake of posting...

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

convert is the stringstream object. The convert is true or false based on the execution of the >> operator. Therefore

if (!convert)

actually says "if the previous operation was not successful..."

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

Just test each character in each position to see if it is of the proper type. Look up the is[I]xxx[/I]() functions, like isdigit() and isalpha()

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

I dunno, WaltP. I'm still in disagreement. Photographs on the web might be copyrighted by that photographer for his portfolio. It may not be right to take those images without asking and use them in your own promotional materials. Don't photographers specifically earn a living by taking pictures of actors and then earning royalty fees when their photos are chosen to be used in various promotional materials?

Please understand the scenario I laid out:

Many times with the variety show I produced, I needed a picture and description of a performer for the advertising.

Without advertising, the show is a bust. Entertainers actually have those pictures and bios for advertising purposes. And many that don't have special promo materials (and that's most of them) expect you to download information.

Yes, photographers earn their living by photographing performers. But the pic are the performer's property. If I design a graphic for DaniWeb and I hold the copyright, you would have to get my expressed permission for every use. Can you see a performer asking permission to send out 200 pics to the plays and movies he's applying for, not to mention 10,000 autographed pictures to be sent to fans? No, the photographer generally does not hold copyright on the pictures. They are the subject's property, a service bought and paid for.

The copyright is held by the person/entity who purchased the shoot, I believe. That's why the photographer has the person sign a waiver that the picture may be …

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

I wonder what BS here stands for... ;)

Bumm Steer... I think :twisted:

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

Oh, Salem, you're so funny :D

All compiled languages are converted into machine language by the compiler. Then finally into executable code that the operating system executes.

Also, please read this

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

OK:

#include <stdio.h>
int main(){char ch[]={83,111,114,114,121,44,
32,119,101,32,119,111,110,39,116,32,100,111,32,121,111,117,114,
32,104,111,109,101,119,111,114,107,32,102,111,114,32,121,111,
117,46,10,73,39,118,101,32,97,108,114,101,97,100,121,32,112,97,
115,115,101,100,32,109,121,32,99,108,97,115,115,46,10,0};int i=
0;while(ch[i]){putchar(ch[i++]);}return(0);}
Salem commented: Touche - Salem :D +6
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

you need kbhit()

That's nice, do you think system("cls") is standard and cross platform compatible?

This was hilarious!!! Suggesting a non-standard function then pointing out something that's not standard! :) Decide which side of the standard you sit on and stay there, don't vacillate.

Also, system() is a standard library function. It's the parameter "cls" that's system dependent.

You don't have memory leaks. You have a runaway program that will take whatever resources it wants.

Fix the kbhit() problem, and that will correct most of it. (if you knew to use kbhit() you certainly can find out how to use it)

Fix your input then we'll get the timer thing working...

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

Please format your code so it's readable. I see this has already been suggested. Please do it...

switch(lose)
{ case 'y' : main(); break;
case 'n' : printf("ok, see ya!\n"); break;
}}
}

Never call main() . Put the program into a loop instead. Then you can simply read the response and automatically loop back to where you need to restart.

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

Just a warning...

printf("Beware the null char is not at teh end of supplied length: %s", equetion ) ;
}

So? We aren't dealing with a string at this point. It's an array of characters. An array of character values does not need a null at the end. Only an array of characters representing a string.

Reason: In my programming a calculator I am ending up with some what is fairly convoluted code to essentially make it take any equation entered, compute it and return its output. And I would like to save 8 lines of code and hopefully a few steps for the processor.

This is a very bad reason to do anything. Assess what something easier means. Does it make the code harder to read? Do you have to resort to tricks to accomplish your goal? Will these tricks compromise maintainability (making it harder to change the code later)? Just trying to save a couple nano-seconds of processor time is not a good thing. Readability should not be compromised.

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

E.g. change:

cout<<"\n Welcome to the gas station\n";
cout<<"\n\nEnter the kind of fuel you want to buy\n\n-->";
cin>>carb;

to

cout<<"\n Welcome to the gas station\n" << flush ;
cout<<"\n\nEnter the kind of fuel you want to buy\n\n-->" << flush ;
cin>>carb;

Better (IMO):

cout<<"\n Welcome to the gas station\n";    // Don't need the flush on this line...
cout<<"\n\nEnter the kind of fuel you want to buy\n\n-->" << ends;

cin>>carb;

The ends ends an output stream and flushes the buffer.
But why would you want to output:

Enter the kind of fuel you want to buy

-->(input here)

Why not just output:

Enter the kind of fuel you want to buy: (input here)

:?:
Save all that blank space and use cout<<"\n\nEnter the kind of fuel you want to buy: " << ends; And don't forget that endl is the same as ends with a newline.

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

Gotcha.

I did a little work on it and so far this is what I got. For now I'm just trying to print each combo on a different line.

int arr[]={3,5,3,7,4},n=5;
 
void combos(int pos)
{
int i;
printf("%d",arr[pos]);
if(pos<n)
for(i=pos+1;i<n;i++)
{
printf("\n%d",arr[pos]);
combos(i);
}
else printf("%d",arr[pos]);
}
 
int main()
{
char c;
products(0);
scanf("%c",&c);
return 0;
}

I think I'm on the right track but I'm definetely missing something. Any ideas?

#1) Format your code. It helps readability and understanding.
#2) The function products() doesn't exist.
#3) The function combos() is never called
#4) See this about scanf() and characters. Look at the entire scanf() series.
#5) putchar() a '\n' when you output the last value of the combo. No need for a printf() for a single character. Ever.

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

hi,
You are righ from your pont of view,, But i would like you to look at the broader part of it..
If u see then u may realize that the whole videostreaming and video uploading etc is possible just because of Flah only and more over it is not just a web enhancer it is much more that that,,,

So you are saying there would be no video streaming without Flash? Somehow I don't think that's true. I doubt most professional video streaming uses Flash.

Yes I know it's much more than a web enhancer. My point is that IMO it should not be used to create websites. There's a heck of a lot it can do, that doesn't mean it's the best tool for all of it. That's like saying because salt is one of the best flavor enhancers, it's all you should use.

And if you look at most of the important sites that do what you say, I can't think of one that's written in Flash, they're all enhanced by Flash.

> I have to screen capture the window and reedit to use a graphic
It would be against copyright laws to use a graphic off of a webpage. For example, I wouldn't want people to steal the graphics I created for DaniWeb and use them in their own publications or documents.

Yes using copyrighted material is not a good thing. I'm talking about research, generally. I find some information …

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

What kind of trouble? Unless you show us what you've tried, we can't help. Be sure to read this and this

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

Are you in school? (let's assume you are for the moment) Do you have classmates? How many? And how many in the whole school? (let's use 1000)

Would you want to define a single variable for everyone's name, then another for address, city, current class, grades so far..... That's 1000 distinct variables for the name. Another 1000 for the addresses. Another 1000...

I wouldn't. But one variable for the name, one for the city, etc, as an array and you have all the students in the array and you can get the information easily from just a few variables.

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

I would suspect you don't have space allocated for the array. How big is the array you defined? Or have you defined just a pointer?

Can't tell from what you've posted.

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

Stuck with what? Maybe this will help... ;)