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

I'm back too... just saying.. XD

HIDE!!! :icon_twisted:

Portgas D. Ace commented: ;) +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

That's not broken English, that's leet, AFAICT

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

You do not need to use the stl library to calculate the min / max . Try writing the code on your own .. Let me give you a head start

For Min.

1. Create a temp variable and give it a value of 30,000 [or any such large value].

Set the temp variable to the first element of the array.

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

Last question, how do I know where to initialize the variables?

You initialize a variable where you require it to be a specific value.

In other words, why is delay = 0; initialized in "for-loop: i" rather than "for-loop: k"?

Study the loops. What happens if you initialize it in the K loop? Does the code still work? If not, that's not a good place.

You have to analyze the code to determine the best place.

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

Yes. And no. It depends. All you really need to understand is int delay; creates a variable with an unknown value. Don't use it without setting a value. int delay = 5; creates a variable with a known value. delay = 5; sets an already created variable with a known value.

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

Someone please give a look to this problem.. http://www.codechef.com/problems/PALIN/

I tried submitting the above solution but its giving a runtime error.

104 posts and that's the information you give to a problem -- "gives a run-time error"? :icon_rolleyes:

My car makes a squirsh noise. Please tell me how to fix it...

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

Because the dates are stored as character arrays, not strings. A string ends in with '\0'. You have space for the date only: 01/01/2012 = 10 characters.

Define your dates as 11 or more characters make sure you load a '\0' in the 11th position.

Also, see this about using gets() and scanf()

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

Where is array[] defined? What line number?

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

Because you are using .eof to control your loop. See this. feof() is exactly the same.

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

Look at your function again. What does it return? Why does it return those values? How can you use these values to control your loop?

There should (probably) be no IFs in main() because it's not needed.

Now, as I implied before, don't try to fix your other code. Just rewrite main() from scratch, putting more thought into how your function works.

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

#1) You use a single IF to test if the first letter returns from your function good or bad. After that first test you never test the return from the function.
#2) Your instructions do not mention exiting on 'a'. I'm certain you should exit on an 'error' return from your function.

Rethink your problem.

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

My psychic powers aren't working well, your code is coming in cloudy... All I can sense is there's something wrong with it.

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

Maybe changing from XCode is in order...

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

Something like this?

Loc[1] = textLength;	
	Loc[2]= textLength;
	Loc[3]= textLength;
	Loc[4]= textLength;
	Loc[5]= textLength;
	Loc[6]= textLength;
	Loc[7]= textLength;
	Loc[8]= textLength;
	Loc[9]= textLength;
       Loc[10]= textLength;

:$

Yeah, kinda like that.

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

What does your error checking tell you of the open and write?

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

Do you know how to do it if you defined the array as int Loc[100] ?
It's the same...

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

What are navigation breaks?

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

My guess is you didn't initialize your values after finishing your first file. Pointers, counters, and flags are probably still the same values they were at the end of the file and not properly set back to their initial state for the next file.

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

I wants to not help cheat.

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

But if there is some interest, and if the interested parties are willing and able to ensure that incoming questions would be addressed with reasonable promptitude, I don't see the harm in giving it a try - let it run for a year and see whether it gets traffic. If not, zap it.

Who knows, I might have obj-c questions in the next year, I might like to see such a forum... :)

Makes sense. Start the forum and if there's no traffic to speak of, move the threads to Legacy and kill the forum. This way you know for sure if it's a viable entry in the list rather than guessing.

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

Ok. Now what?

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

Dear All,

Kindly go through the following program.

Dear rpstata,

Kindly remove all extraneous blank lines (and comments) and indent your code properly so we can follow it.

Then we can understand the program flow and it will fit on our screen and help mucho bueno.

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

Just test the end of the string for 0x0A and replace it with 0x00. Then test again for 0x0D and replace with 0x00.

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

If \n is the EOL character, how can it not be the EOL character? "if '\n' is a legitimate part of the string data" is meaningless if it's defined as an EOL character. You need to decide how you define what. And since you didn't really answer my question, all I can say whatever you are doing must be wrong and I don't know what you ultimately want.

Your description makes cursory sense but when we get down to the little details, you try to describe (rather than show) in a confusing and detailless way what you want.

Ever hear the adage "a picture is worth a thousand words?"

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

That completely depends on what you really want the string to look like when you're done.
If your string is ABCDE\n98765\nalpha-omega\n , what do you want it to contain when done?

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

This leads me to thinking that maybe I can't just replace the "\r" and "\n" characters, but everything I read suggests that it's the combination of the two that Windows uses to represent EOL characters.

Correct...
Windows uses <CR><LF> combination
Mac uses <CR> alone
*nix uses <LF> alone

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

and i don't get what's with this " if character = '\0' -- this will indicate a function key has been pressed"

A function key is actually 2 characters. Try this code:

#include <stdio.h>
#include <conio.h>
int main()
{
    int ch;
    
    puts("Hit Keys: ");
    do
    {
        ch = getch();
        printf(" <%02X>", ch);
    }  while (ch != 0x20);
    return 0;
}

Press SPACE to exit

You should write small snippets like this to test stuff you are unsure of. It saves time and you learn a lot more by writing even more code.

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

Actually, you don't need the && at all. And you can shorten your code dramatically by looking more carefully at it:

if (weight <= 18.4)
    {
        cout << "Your BMI is " << weight << " you are underweight." << endl;
    }
    else     
    if (weight <= 24.9)  // weight cannot be less than 18.4
    {
        cout << "Your BMI is " << weight << " you are average." << endl;
    }
    else     
    if (weight <= 29.9)  // weight cannot be less than 24.9
    {
        cout << "Your BMI is " << weight << " you are overweight." << endl;
    }
    else     
    if (weight >= 30.0)
    {
        cout << "Your BMI is " << weight << "you are Obese." << endl;
    }

    getch();    // All your tests do this, so do it once.
    return 0;
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You keep changing what you ask for. Now answering:

let say that:
num=num2/3
num1=num3/5

how to make random between num and num1

Assuming num < num1: random-number = (rand() % (num1 - num)) + num

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

can anyone let me know if what i'm doing here (the collision checking) it's ok??
the code looks something like this:

#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77

void right(int &x, int &y, int sta, int end, int r){
do{

map();
	setcolor(YELLOW);
	setfillstyle(1, YELLOW);
	pieslice(x, y, sta, end, r);
	x+=5;
	delay(100);
	cleardevice();
	}while (!kbhit());  //i need to know over here too what to modify
}

do{
		
		for(i=1; i<=21; i++){
		for(j=1; j<=25; j++)
		 input=getch();
		 if (input==RIGHT)
				if(a[i][j+1]==0) right(i*20+5, j*20+95, 100, 100, r);									      //else - do nothing, it's a wall
				if (input==LEFT)
				if(a[i][j-1])==0) left(
				.......//and so on
		
		}while(input!=27); //stop when ESC is pressed

Not really.
You don't need 2 loops. One will suffice. Inside that loop:

If kbhit() returns TRUE
   get a character (getch())
   if character = '\0'  -- this will indicate a function key has been pressed
      get a character
      set up a switch on the character
         case of UP,DOWN,LEFT,RIGHT - process the direction key
      endswitch
   else
      process a non-function key
   endif
endif
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

And I misread also... It must be catching.

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

Line 13

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

See this. You do not want to use gets() . It's dangerous.

And your s2 definition is OK since you have it defined at 30. Dragon misread your code.

And strlen() returns the length of a properly formatted string.

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

#1) Forget the game board. Just work on input of the guess and output of the result. Isn't that the important part of the game?
#2) I don't see a class defined anywhere. That's probably why you can't get it correct.

My suggestion:
a) Write the class and code to choose the colors to be guessed. Add to the class just the information you need at this point (the initial colors). Do a simple output just to be sure you've got that correct. Once you do...
b) Add a function to accept the player's guess. Simple output of the guess and keep fixing until you get this part correct. Then...
c) Add a function to test for colors in the correct position. Again, simple output to see that this is correct. Keep adding to the class as you find things you need to keep track of.
d) Now, start working on the actual game output function (no difficult 'board', just a simple display so you can follow the game).

Keep adding a piece at a time, as functions, until you get it working. The 'game board' is one single function. Once the game is running, you can then massage the output to look like a board.

Oh, and read up on where the srand() function should go. It's not where you have it.

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

I still stick to the fact that learning from code is far better than getting hints...

That's fine. You can post code, just don't post complete answers.

Example: "I need to write a Fibonacci series" and they post whacked out code. Don't write a fibbo series for them, write something else that illustrates the solution to their code errors -- like adding even numbers. They can then learn from your code and fix their fibbo code with the ideas you post.

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

That doesnt answer my question on line 32!

Yes it does. You'll have to tell us why it doesn't. All you have to do is look at your line 32 and compare it to their command.

Justntell me the command please.

We would rather you learn, not just let us do it for you.

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

I have a novel idea -- talk to your teacher? I remember them helping me when I was in school.

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

Output a prompt asking for filename
Input as string
Use the string in FindFirstFile() as per the definition of the function.

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

So my suggestion makes no sense to you? Why not?

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

How is your array defined? How does it reflect your map?

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

Look up the OPEN command again. I believe you have it wrong.

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

CORRECT CODE.....

1) It's not correct code
2) Do not do homework for others. It's not your grade, and it is their future.

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

WaltP, I am trying to compare with my IF statement, not the number zero, but the value of zero, which is nothing,

What is the difference between the number 0 and the value of zero ? And what is the value of nothing ? None of this makes any sense. Please describe again what you are doing and don't mention zero because it means nothing in the context you are attempting to describe.

That is why I had &0 because I thought that it would make it a space, since the value of 0 is nothing.

No, &0 is the address of the constant zero -- which has a value -- the address.

A SPACE is not 0, it's 32 decimal, 20 hex.

The value of 0 is 0. nothing is meaningless as a value.

Like for example, when I put it 105, it would return (weird symbol)(letter)501, but I would ideally want it to be (space)(space)501. And eventually just 501 with nothing following it or before it.

You are using a character array. So, if the array element is a digit ('0' thru '9') then print it.
If the array element is not a digit, print a SPACE.

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

Ah, that is my bad. I don't get to use the internet as much as I used to so I tried remembering the IF statement from memory, lol bad idea. Anyways, I put it in the right format now...

Try again. =? No.

... and I am wondering how exactly or what exactly to put in after the = sign in my IF statements...

What's the purpose of the IF? What do you want to compare your value to? That's what goes after the ==.

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

Does your getData() function work? If it doesn't, you don't need to work on the print function yet. When programming, take it a step at a time.

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

You need to look up the format of the IF statement. Not one of them is even close to being correct.

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

Who cares? If you really want your -40 back I'm sure we can down vote all your posts in this thread to get you back there if you really want us to.... :icon_rolleyes:

jingda commented: You are so bad +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Write it up and post it here. If it makes sense, Dani can move it where it will do the most good.

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

...but I have one problem

No, you have many problems.
1) Using bold, underline, red text, lines of hyphens to make your post look cute. It's unnecessary and distracting. By the way, you forgot to use italics.
2) Your formatting is bad -- see this
3) void main() -- main() is never a void, see this
4) clrscr(); -- useless and annoying for the user, and hasn;t been available in compilers since 1990
5)

if((fp = fopen("samplete.txt","r"))==NULL) {
printf("cannot open file.\n");
}

What happens if it can't open the file? You continue anyway
6) gets(code2); -- extremely dangerous, see this
7) while(!feof(fp)) -- error prone loop, see this

You might want to learn from a better source. Your current source seems to be older than the hills, and is teaching very bad techniques.

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

Ok, I've been trying to run this program on Borland C++ (Version 5.0A). The program is a Point of Sale program. I keep getting the errors "expression syntax at (121,26)" and "If statement missing ) at (129,6). Try as I might, I can't seem to fix the errors.

I don't see anything wrong with line 121: if((command == UP) && (wherey() > 2)) nor line 129: } But on 119: while(command != 17); if command == 17 you have yourself an tight endless loop. You might want to get rid of the ;