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

Because you are expecting the language to do the work for you. When you read strings, you need to deal with the strings yourself. And since we have no idea what you are reading and trying to do, it's hard to point you in a direction.

You need to understand the commands you are using. Not just throw them in because you heard of them. Your fscanf() call is wrong.

Use fgets() and break the line up yourself.

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

Hi,
Use the below code.

Private Sub Form_Unload(Cancel as Integer)
Msgbox "This form will close because you have clicked Close button on control box.", vbOKonly
End Sub

Above example will display message when you clicked the close button.

Hope this helps.

What happens if you click the exit button which is supposed to close the form ? Or execute the statement Form.unload ?
Think again. Or actually, read the posts in this thread...

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

Doen't your book explain it? Or your tutorial site? What about Google?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
char input;
    char output;

    cout<<"Enter input file name : ";
    cin >> input;
    cout<<"Enter output file name : ";
    cin >> output;
    while(!in.eof())    // in is not even open, it can't be at EOF yet
    {
    in.open(input);   // Open in
    while(false)
    {
        if(in.fail()) // If in is in failure state -- but nothing  
                     // is ever done with in to make it fail 
        {           // except open.
            cout<<"input file did not open please check it\n";
            return false;
        }
    }
    out.open(output);
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Look up the unload or terminate event handlers for your form.

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

In the same scope, yes.
In different scopes, no.
But it could be very confusing to anyone reading the code. Generally not in functions as you have them, though.

Be careful if defining variables within code blocks ( if , for , while , ect)

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

and perhaps Walt you should recognize that this thread is in the wrong forum and have moved it to the VB.NET forum...

Since I don't know VB.net, maybe I wouldn't... :icon_wink:

I'll move it, though...

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

I am not so sure what you mean. My current code is:

Maybe you should have posted this last time... :icon_wink:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim myfile As String = "C:\Users\londonG\Documents\lillefile.txt"
        
Dim TextLine As String

        If System.IO.File.Exists(myfile) = True Then

            Dim objReader As New System.IO.StreamReader(myfile)

            Do While objReader.Peek() <> -1
                TextLine = TextLine & objReader.ReadLine() & vbNewLine
            Loop
            TextBox1.Text = TextLine
        
        End If
    End Sub

Where should i put the if statement. Is it inside the loop?
How should I write it?
Thank you

Are you asking me to write it for you? What does your code do currently? Where do you think the if should go?

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

The language cannot define an array of indeterminate size. You must give it a size. One option is to make j a pointer instead and dynamically create the array with new .

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

A mid-90's Alicia Silverstone movie pops into mind for some reason.

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

Read the file line by line and when you get to the line you want, stop. Might need an if statement

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

Post the freakin' errors. We can't help you if you keep the errors a secret.

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

Did you define the deal() function to take parameters?
If so, did you pass parameters on the call deal line?

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

see I don't quite know what's wrong. whenever i hit the comand button, I get an error saying "argument not optional" and I don;t know what that means, I'm thinking that there must be multiple problems that I cannot see.

Neither do we. If you are really using Visual Basic, in my experience the program stops on the statement that is causing the problem. That might be one of the details you need to give us -- the line in error. And a couple lines above and below in case they might shed some light on the issue too.

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

Hey, I'm a student with rudimentry knoledge of VB6 and I've a college project where I have to develop a blackjack game. Unfortuanately I've a problem with the method I call the cards I was wondering if any of you would be able to shed some light on the problem.

You didn't explain the problem. You need to give us details. Don't make us try to understand the code you wrote that you can easily describe, without an explanation of what the trouble is.

Details, please.

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

A couple things to mention:
1.) This program uses system("PAUSE"); in the main function, if you are not using Windows, you might have to pull it.

Then you shouldn't use it at all. Keep your programs Standard so you don't have problems when you change compilers. See this.

HERE IS THE PROBLEM
I like to use (sizeof("Array To Be Used")/sizeof("Array Type")) to determine my Outer Loop limits.

Why? If you set up the array to be 5, use 5. Just make it a constant at the top of the program so that when you want to change the size you only need to do it in one place.

When I check the Arrays sizes right after I populate the data in main, everything is good. When I pass them to the function, they go down to 1 Element.

So when I am in the function findLowest and I try to get (sizeof(accidents)/sizeof(int)), it returns 1....

I'm wondering what I'm losing when I pass my int array through a function that only see's the array as one element (Although when I force it to show me each element it will, the sizeof( ) just isn't seeing the big picture....does that make sense?

You are losing the fact that there is an array. All the function knows is a pointer was passed in. It has no idea how many locations are associated with the pointer. You need to also pass the size into the function.

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

As you obviously know, you divide out the last 3 digits and call the function again.

When you divide out the digits and your source is 0, you have the highest value as a result (the 45 from 45,652,567)
Output it and return.

The return loop then outputs ',' followed by the precious result.

So a minor change to you function should get it. Think if-else when you get your result.

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

You always output the 3 digits followed by ','. Assume you have 10. Follow the code with that value to see why the comma is output.

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

Instructor being 'C++ For Dummies'.
:$

:icon_razz: plbbbbbbb..


:)

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

Useful tips:

you can consolidate lines 13 through 33, and eliminate lines 37 through 44 by doing this:
---
Furthermore, keeping your choices in array format would simplify your code:

Assuming he's learned arrays. If not, instructor may not like it...

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

Yeah, figured you had a brain fart and could correct it easily... :icon_wink:

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

That's because each line you mentioned is extremely wrong.
Look up do-while loop to understand the syntax of the statement.

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

How can you not find information on CODE TAGS
1) in the Rules you were asked to read when you registered
2) in the text at the top of this forum
3) in the announcement at the top of this forum titled Please use BB Code and Inlinecode tags
4) any place CODE tags were used, even in responses to your posts
5) Even on the background of the box you actually typed your message in!

kvprajapati commented: nice reference for me, sir. +7
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Have you learned anything about converting numbers to strings? Any string manipulation at all? If not, you do not have the knowledge yet. Give it a couple weeks and return to this question. You should have the concepts by then.

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

Sure. See this and specifically this

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

Looks to me like you need to explain in detail what the problems are -- and where in the code you're having problems. I don't see a problem in compShip() which it sounds like you're complaining about.

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

If the missing values are always the last in the line, then as jonsca suggests read teach line using fgets() then use sscanf() to read the line into the variables.

But you also mention "a bad character". Do you mean there are letters in the input that will mess things up? If so, your task is much harder.

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

Although not perfect, your formatting is much better. Thank you.

I am getting a compile error I do not understand on the line printf statement right below the end of the do while loop. It says printf identifier. Help?

That's because there is no such thing as a do while statement. It is a do-while loop:

do
{
    -- stuff to do --
} while (exit-condition);

Did you look it up before using it?

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

That's just as bad. Try clicking on the link. I put it there for a reason.

Or maybe you can explain how

int main()
        {
	      const int PEOPLE = 5, PRODUCTS = 6;
       double sales[ 5 ][ 6 ] = { 0.0 }, value;
        double totalSales, productSales[ 6 ] = { 0.0 };
		int salesPerson, product;
   	    int  i, j;
 
       salesPerson = 0;
	   product =0;
	   value = 0;

shows consistency in indentation.

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

Please use punctuation so we understand your question. Your 1st sentence is barely understandable.

Please read this, and note the title.

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

Please format your code consistently. It is very hard to follow when indenting is all over the place with unnecessary blank lines between every statement.

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

Here is what I have so far. Suggestions??

I suggest you explain the problem. We aren't psychic...

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

If you are working with array[j] you need to update bday[array[j]]

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

Yet another way to keep the count:

Have an array of 366, maybe call it bdays[366] (one extra to skip day 0)
In your code, array[] keeps track of which b'day each person has...

So, if array[0] has a b'day on 122, increment it: bdays[array[0]]++; You've just counted that b'day.
Next person's b'day on 68 - bdays[array[1]]++; etc.

When done, if bdays[5] == 3 then 3 people had b'day on day #3.

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

error LNK2028: unresolved token (0A00000F) "extern "C" int __stdcall GetUserNameA(char *,unsigned long *)"

Where is GetUserNameA() defined?

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

First thing I see is using C-style headers and C input. Get rid of all the C headers ( conio.h, stdio.h ) and stick with iostream . With that, don't use _getch() . Use C++ input commands. math.h should be cmath , the C++ version.

Fix that and if still a problem, describe in greater detail what is happening.

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

Hi frens,
I couldn't compile this solution code given by my university on visual studio.Visual studio works fine with other C++ files.

Why not? Does your machine crash?

When asking for help always give enough information so someone that is not in your class or can't see your screen can understand the problem. Full disclosure -- what happened, what went wrong, what was supposed to happen? At least.

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

My assignment is to compare the files char by char... believe me i wouldn't be doing it this way if i didnt have to. we have to report the line the files are different so using getline makes that part easy.

Another option then is to read the files one character at a time. When you read a \n, increment the line count.

I wouldn't change to this now, but next time it's something to consider.

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

One thing I'm wondering is if you are reading the entire line from both files, why are you checking character by character? Couldn't you just compare the lines as read? if (s1 != s2) You are using strings, which can be compared with ==

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

I am not attempting to insult you.

Waltp i think every person has a common sense kind of thing. As you can see that he has appriciated my answer by saying "Thanks 4 that garbage char prob". I just try to solve his problem of reading char by char. It is easy to reverse a buffer as compared to a file.

As Dave points out, and using your terms, common sense dictates that if someone says "Thanks 4 that garbage char prob" and you never mentioned garbage char prob, he wasn't thanking you. Maybe?

I also stated "This is the second bad info I've seen you give in 2 posts." Anyone that seems to habitually give bad information should "think before you answer questions." This is also "common sense".

Please notice that your reputation indicator is not green. This is indicative of something. Maybe "common sense" is not that common.

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

Also your if clause should be like this:

If dbltotalaverage >= 90 Then
                txtgrade.Text = "A"
            ElseIf dbltotalaverage >= 80 And dbltotalaverage <90 Then
                txtgrade.Text = "B"
            ElseIf dbltotalaverage >= 70 And dbltotalaverage <80 Then
                txtgrade.Text = "C"
            ElseIf dbltotalaverage >= 60 And dbltotalaverage <70 Then
                txtgrade.Text = "D"
            Else
                txtgrade.Text = "F"
            End If

Not really. This should suffice:

If dbltotalaverage >= 90 Then
      txtgrade.Text = "A"
   ElseIf dbltotalaverage >= 80  Then
      txtgrade.Text = "B"
   ElseIf dbltotalaverage >= 70  Then
      txtgrade.Text = "C"
   ElseIf dbltotalaverage >= 60  Then
      txtgrade.Text = "D"
   Else
      txtgrade.Text = "F"
End If

The second part is not necessary because the comparison preceeding takes the < into account already.

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

Instead of reading character by character use "fread" to read more than 1 character from file at a time. And then use "fwrite" to write them to the output file.

You can also use "fgets" to read a file line by line. Because "fgets" terminates reading on "\n" (new line escape sequence).

And how does this help the OP write the "output file in reverse order" better than what he's done?

Please think before you answer questions. This is the second bad info I've seen you give in 2 posts.

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

Yes Jonsca, I have already read that and I was wondering if there is one single function within standard library.

No.

I saw somewhere string::Substr() and I'm trying to check if that is what I want.

That is one way to do it.

Anyway the bad of C++ is that there is no official Manual to download and look like other languages (PHP, JAVA, PYTHON et al)

There is, sort of. It's called The C++ Standard. But most any C++ 'manual' on the web will give you the info you want.

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

Buffered output is probably the problem. End the cout line with flush to empty the buffer immediately.

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

You are dealing with floating point numbers. .99 probably is stored as a close approximation of .99, very close. But not close enough. Same with all the other values. Therefore, you have a little wiggle in the values and probably end up with something similar to -0.000000001 as an answer.

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

Nathan is right. Change the for statement. You can better write the for as for (;!ifs2.eof();) which is really a while() Also, as he says, you read off the first line of file 2. Then

for( int i = 0; !ifs2.eof(); i++ ){
    getline( ifs2, s2 );  // Read line from file 2

    if( !ifs1.eof() ){
      getline( ifs1, s1 );  // Read line from file 1

      c1 = s1[i];       // get the first characters of each line
      c2 = s2[i];
      if( c1 != c2 )    // compare the first characters in each line
        cout << endl << "Files differ at line" << (i + 1) << endl;
    }
  }

So, if the first character if each line matches, the files are the same.

Here's why you don't want to use .eof() -- feof() in C is the same as .eof()

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

As Narue implies, the !! is 'converting' the integer value to boolean.

The !x equates to true/false. The additional ! reverses the value. So if x = 23 (which is an implied true), !!x is 1 (strict true).

If you need a strict true, it's obviously useful, but if b is a boolean type, b = x; seems to accomplish the same thing.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
/*part of solution by WaltP */
#define UINT_BITS ( CHAR_BIT * sizeof(unsigned int) )
#define rotateleft(x,n) ((x<<n) | (x>>(UINT_BITS-n)))   
#define rotateright(x,n) ((x>>n) | (x<<(UINT_BITS-n)))

Be more careful quoting. I never posted in that thread nor did I write that code.

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

Do not start new threads for the same question.

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

Guys,

Thanks so much for your replies.
It's been six years since I made this newbie post. :)) I'm a bit surprised that someone else is still replying to this. Makes me happy, though.

Doesn't make us happy.

Rhetorical question: With the help of abhimanipal and whgeiger, can you now finish your program? That should give you an idea why we're more annoyed. :icon_wink: