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

BytNum -- ByteNum[x] = StrNum[x] - '0';

I didn't get what you are trying to do here. Could you please explain.

Converts the character value to a binary value. Look at an ASCII chart and study all the values in the code -- in binary.

And I agree with the fact that this solution will do addition and subtraction with ease. But what about multiplication? Am I supposed to take each byte by byte and multiply just like manual multiplication?

Yes.

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

Here's my approach:
Read the value into a string (StrNum for example).
Create an byte array StrNum.length in length (ByteNum).
Convert each character in StrNum to a byte in BytNum -- ByteNum[x] = StrNum[x] - '0'; Now you can use ByteNum to do all the math.

This way you don't have to deal with any size issues, non-standard type definitions, et al.

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

That's because values like 0x0001 and 0x012 are not printable characters.

See this. Printable character are basically 0x0020 to 0x007E.

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

So 'add' the values rather than test the values.

If you add '1' (31h) and '0' (30h) together you get 'a' (61h). Subtract out the extra 30h and you have your character:

'0' = 30h
'1' = 31h
'2' = 32h
therefore:
'0'+'0' - 30h = '0'
'0'+'1' - 31h = '1'
'1'+'1' - 32h = '2'

The only IF you need is testing for '2' and convert that into '0' + carry Or you can add all 3 values and subtract the extra 60h. Then you have to deal with a possible '3', just like above.

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

if(strcmp(s.name, stdname)==0)
is this statment is correct? i am having an error while executing this statment.. i have givn its headerfile

Depends on how s is defined.
Depends on how name in s is defined.
Depends on how stdname is defined.
Depends on what headers are included.
Depends on what the error is since there are hundreds of error messages possible.

As it is, the statement is syntactically correct.

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

My point is we do not condone posting working programs as a starting point for a poster. We help him write his own code. The program does a large chunk of what the OP needed -- enough that the homework would not be his.

If cangan had posted psuedo-code, I would have no problem with the post.

My comment stands.

PrimePackster commented: Agreed +3
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Try this

And what grade do you expect to get for doing sodha125's homework for him? Around here we call that cheating... Good job!

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

im newbie to vb 6..

So?

can anyone give the codes in viewng the database in listview and when you double-click one of the data in listview the second form will appear or the information of click will appear..

What makes you think we're a homework service for lazy students?

thx.....
i need your helppss....for my project..
plssssssssssss
help me.......
tnx...................

Whiney elementary school at that... :icon_rolleyes:

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

but the text in form1 is retrieved from a database.

Different question. so you need to make new thread.

What? Same question. Additional info. And there's no problem asking 2 questions in the same post... :icon_rolleyes:

Thanks for your reply. Im new to VB6 will this work in VB6..

In the VB4/5/6 forum, we tend not to answer using Python techniques. That would confuse people. :icon_wink:

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

I don't see any personal info. There seems to be nothing to delete.

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

Well, you you are going backwards and just broke your solution.

What is remainder?
What is the result of hex[remainder]?
What happens to that result without an = sign somewhere?
How does changing [remainder] to [answer % 16] solve your problem?

You need to start thinking through the problems, not using a shot-gun technique and hoping you hit upon the solution by trial and error.

Although it is a different task, this thread has a bunch of concepts spelled out you can use while trying to understand this weird programming lifestyle.

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

Oops. Sorry. I tend not to bother reading posts that are 7 years old... My philosophy is if there's a problem, let it stay buried rather than dig it up and let it live yet again. That may be just me...

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

Yes. But you might want to do a sanity check on what you have. Did you in fact read the file and store it correctly? All you checked was reading the file.

What if your names file doesn't open? Why would you still want to read the file?

Why are you writing what you read to the transpose file? Isn't it supposed to contain the transposed names? For that matter, why do you even have the transpose file open yet?

What are you doing with trans in line 24? Why are you reading an integer into it? What are you doing with that integer?

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

Except what's that loop for?

And what are you doing with hex[remainder];?

I know you probably think I'm dumb... But I'm trying to understand. Arrays are very new to me

No, just inexperienced. We were all there at one time...

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

It's just Opera telling you to look forward. Leave the past behind you... :icon_twisted:

diafol commented: :) +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Some people it's inherent. Other can never understand it. You seem to be somewhere between and haven't worked at developing it.

Have you ever done what I just did with any code? If not, you have not been a programmer. A programmer is a detective that searches for reasons why things work and don't work. It looks like you haven't done that yet. Starting now, be much more analytical in all -- that's ALL -- the code you write. Once you get something finished, make a copy and rewrite a small section with a slightly different idea. Then analyze the results. Why did they both work? Why did one work and not the other? Narrow down the difference and keep a journal of the things you find so you can refer back to them and not make the same mistake 5 more times.

Here's an example. Remember that link I gave you? Now here's your working code with a minor change removing unnecessary lines:

while (file)
{
    file.read( (char*) &rec, sizeof (account) );
    if(!file.eof())
    {
        rec.display();
    }
}

We now know why this didn't work:

while (!file.eof())
{
    file.read( (char*) &rec, sizeof (account) );
    rec.display();
}

But why does this work? It still uses .eof() ...

file.read( (char*) &rec, sizeof (account) );
while (!file.eof())
{
    rec.display();
    file.read( (char*) &rec, sizeof (account) );
}

When something doesn't work as expected, don't just muscle through to the answer, changing things and hoping it worked.
1) Completely …

deceptikon commented: A case of mistaken identity, I think, but great reply nonetheless. :D +3
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What's the value of 40! ?
What's the largest value a variable can accurately hold?
Rim-shot!

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

Here's the function that I've made to do this, however, it's not perfect. It only works correctly for single digit numbers. Double digits and up are problematic.

//converts answer in decimal to hex
void backToHex( double answer )
{
	int remainder;
	int a = answer;
	int b = a / 16;
	char hex[11];
	for (int k = 1; k < 10; k++)
	{
		remainder = a % 16;

		if (remainder == 10)
			hex[k] = 'A';
		else if (remainder == 11)
			hex[k] = 'B';
		else if (remainder == 12)
			hex[k] = 'C';
		else if (remainder == 13)
			hex[k] = 'D';
		else if (remainder == 14)
			hex[k] = 'E';
		else if (remainder == 15)
			hex[k] = 'F';
		hex[0] = b;
		if (b == 10)
			hex[0] = 'A';
		else if (b == 11)
			hex[0] = 'B';
		else if (b == 12)
			hex[0] = 'C';
		else if (b == 13)
			hex[0] = 'D';
		else if (b == 14)
			hex[0] = 'E';
		else if (b == 15)
			hex[0] = 'F';
	}
	if (hex[11] > 0)
		{
			cout << "----------Addition Overflow----------" << endl;
		}
	else 
		cout << hex[0] << hex[1] << endl;
}

If I entered AB for the first input, my output would be: D, but it should be A. Why is that? Is it because "answer" was a double and I changed it to an int? And I doubt that this will handle multiple digits. Any help would be greatly appreciated.

Ouch!
Use a character array for the HEX characters. Use remainder as an …

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

Kudos for using fgets
Bad for using void main() -- see this
Bad for using getche() -- see this
And one more bad for "Here is what I have so far" with no additional information. Is what you posted working?
-- If so, say so, mark the thread solved, and thank the people that helped.
-- If not, explain why not. In detail.

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

If able, i would greatly appreciate any advice or tips that you can offer to help with the alteration of my code.

Good. Since you asked, and I can barely follow your code the way it's indented, I highly suggest
1) using a consistent format, especially with { & }
2) using better and consistent indentation
3) better use of whitespace
See this

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

In Standard C++ there is not. ESC is not a magic key today*. Just use ENTER.


* It never really was. The use of ESC has always been non-portable and much more difficult to program.

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

I did not understand any of that except the part that says the eof function returns true after the end of file has been read, not when it is reached.

If that's true, why does the following code work?
Honestly, both sets of code seem to be the same to me in program flow :|

That's because you are new and haven't developed the keen Spidey Programming sense yet. It'll come...

Follow the code carefully--
Code #1:

while (!file.eof())
{
    file.read( (char*) &rec, sizeof (account) );
    rec.display();
}

A) Test if EOF
B) If not, read the file
C) Process the data


Code #2:

while (file)
{
	file.read( (char*) &rec, sizeof (account) );
	if(!file.eof())
	rec.display();
	else
	break;
}

A) Loop as long as there is no error
B) Read the file
C) Test for EOF
D) If no EOF, process data.

Note the order of the READ and TEST...
Noticing these types of differences is key to programming. And writing out what's actually going on, as I did here, is a major tool to understanding the proper logic.

Just remember, the hard part is writing the sequence of events exactly as they happen rather than writing the sequence of events as you wanted them to happen. You have to be very careful about that. What happens for me as I write the actual sequence, when I get to the error it's not always apparent …

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

A "list of names" by definition is a 2D array.
Each row is one name
Each column is one letter in each name.

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

Portable doesn't have anything to do with the .EXE file that's created. It means the code you write can be built using any C++ compiler.

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

Keep a count of how many values you actually read into the array.

When you read the file, be sure you stop when you hit the end of the file -- EOF.

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

The min value should be 1 if the input is in the sequence originally posted. The program will ignore any duplicate version of min (as can be proven by using a variable to keep track of the index of the element representing min).

Did you miss the term (and description of) unique min? :icon_wink:

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

[boilerplate_help_info]

Posting requests for help must be well thought out if you want help quickly and correctly.  Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful?  Check your post with these checkpoints - what is it [i]you[/i] missed:
[list=1]
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information.
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what happened.
[*]Do [b]not[/b] ask for code. We are not a coding service. We will help you fix your code. 
    If anyone posts working code for you, they are a …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

superblock - Do you need it? You're designing your own system, aren't you? Why try to duplicate something else, especially if you don't understand it?
boot block - You don't need it. You aren't booting anything. Assume this is a secondary drive. KISS.
inode list - This you need in some form -- of your own design.

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

For this type of program, the easiest solution is to sort the input then it's an easy matter to find the unique minimum.

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

No. You obviously didn't bother to read the link I posted.

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

To clarify what DJSAN10 is saying, assuming it needs clarification, in each IF block you are creating a new lettergrade1 which gets destroyed as soon as that block ends. The lettergrade1 value at the top is never used.

Kudos for using the 'proper' IF-ELSE construct and not using else if (s1score >= 0.70 && s1score < 0.80)

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

Commenting your code AND formatting it properly (second suggestion) helps a LOT!!!

for (int x=0;x<10;x++)
{

cout<<"enter:";
cin>>input;         // input a number
if (input<-1)       // if number is -2, -3, -4, and so on...
nega++;             // increment value to count it.
else if(input>=0)   // otherwise if 0, 1, 2, 3, and so on...
posi++;             // increment value to count it.

// what about -1?
// is 0 considered positive?
// The above comments are what's happening. Do they in fact explain what you want to happen?
}
cout<<"positive:"<<posiAr[posi];    // what is the value of posiAr[posi]?  I don't see anywhere 
                                    //where the posiAr[] array has any values in it at all.
cout<<"negative:"<<negaAr[nega];    // Same here.
getch();
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
negaAr[x];               // What's this statement supposed to do? It does nothing.
}

Answer the question. Since this does nothing, we can't for sure tell you are trying to do with it.

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

This is why you get the last line twice. ( feof() is the same as .eof() )

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

In that case it's be 7 right? I'm sorry, arrays confuse me xD

Count the letters...

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

i dont whats thee problem of this, ihave to input 10 integers and display the number of positive and negative.

You have no formatting making the program difficult to follow. See this.
See this too.

#include<conio.h>        // No longer a valid header file.  Very non-standard & non-portable.
#include<iostream.h>     // Years ago the .h version of this header was replaced. Use the current version without the .h
void main()              // main() has NEVER been a VOID.  It's INT!
{
clrscr();                // Worthless and annoying to the user.  Don't use it.
long input,negaAr[10],posiAr[10];
for (int x=0;x<10;x++)
{

cout<<"enter:";
cin>>input;
if (input<-1)
negaAr[x];               // What's this statement supposed to do? It does nothing.
else if(input>=0)
posiAr[x];               // Same with this one.
}
cout<<"positive:"<<posiAr[x];  // What's the value of X at this point? 
cout<<"negative:"<<negaAr[x];
getch();                 // Another non-standard and non-portable statement. Use CIN.
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

If you have the value "ABCDEF" in input, what is the value of input.length()?

If i = input.length(), which character is input[i] ?
Remember, zero based values... :icon_wink:

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

Please use proper formatting techniques, especially on indentation. See this and repost.

... But, I learned a valuable lesson that day, why it is very important to write maintainable code. That first hand experience of dealing with my own unmaintainable code has changed my coding style forever. I cannot emphasize enough, how important it is to learn proper formatting skills, learn from my mistake. I hope you find your bug.

Apart from the fact that it's hard to see what's going on because of the lack of indenting in you post. If the code looks like this on your own computer, then I would expect you to be having problems figuring out what's going on!

White-space can be used to aid readability further (as above). It might not seem like any of this is that important, since the compiler doesn't care about it. However, it's vital for the readability and maintainability of your code.

3 different people, same comment. And you are ignoring each of them! Why should we bother?

FORMAT YOUR CODE!

I suggest no one bother trying to dig through his code anymore if he's not going to bother listening. It'll take 10 minutes to format that mess properly, and save us buckets of time trying to be nice helping him for free.

And stop QUOTEing your text. It's not a quote. Just type it in.

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

Store the last number generated somewhere -- in another table or an initialization file.

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

No. I would ask for clarification. Making assumptions is prone to rewrites and lost revenues. Get a complete description so you don't have to guess.

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

One last comment about yours: what happens when the user hits the RETURN key or Ctrl-D after just inputting the month and day? Is the year still sane?

Yes. Because, since you are discussing best practices, when you test the return code from scanf() you will find all values were not entered and handle the improper input. You do advocate always testing the return values from all functions, don't you? :icon_wink:

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

1. Initialize ALL variables to sane values (if only 0 or NULL) when you declare them.

Unnecessary. Only values that are not read in or set in the code need to be initialized. In your example

int mm = 0, dd = 0, yyyy = 0, mm2 = 0, dd2 = 0, yyyy2 = 0;
   
   printf("Enter first date (mm/dd/yyyy): "); 
   scanf("%d /%d /%d", &mm, &dd, &yyyy);

initializing mm,dd,yyyy are completely unnecessary and a waste of time.

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

Now that you've figured it out, go back and up-vote more of my posts! :icon_twisted:

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

Thanks WaltP. I didn't know that. I posted it with the knowledge that int i = 09; gives an error.
So, I believe scanf will be doing some formatting to 09. Am I right?

No, scanf() reads in what you type into %d (decimal). 09 is valid decimal. It's only the internal use that a beginning 0 indicates octal.

On the other hand, you are correct if you use %o in scanf() .

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

you should use flag and store 1 if 1st date is smaller.and use break; in if block;

Have you ever used a break in an if() block? It doesn't work.

I don't see any validity checks done for your dates. He can enter invalid dates like 33/33/2012.

I would assume validity checks in this program are moot. It's just to figure out how to compare dates in general

day1 = yyyy1 * 10000 + mm1 * 100 + dd1
day2 = yyyy2 * 10000 + mm2 * 100 + dd2

Check which is greater out of day1 and day2. So simple, isn't it :P

Nice. Simple and workable, even with invalid dates. I'd use some parentheses though. Makes the equation easier to read.

But there is another potential error in your program. Your variables mm1, dd1 are declared as integers and in your console out put you ask the user to enter in mm/dd/yyyy format. So for September, the user will enter "09". But since mm1 is declared as int, "09" will be treated as octet number and you'll get run time errors, since 8 & 9 are not allowed in octet system. So better use strings.

Completely untrue. Write a test program and see.

subith86 commented: thanks for the info +3
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Please use proper formatting techniques, especially on indentation. See this and repost.

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

Have to work too hard trying to follow the code with that awful indentation. See this, reformat and try again.

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

Sorry, I'm confused..

matrix = new double[(unsigned int)rows*(unsigned int)columns];

Is 2D right?

e.g.

matrix = new double[10][20];

No. Get rid of all the unnecessary stuff in the line and you get matrix = new double[rows*columns]; Where's the 2D in that? Count the square brackets...

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

Wrong.