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

Actually, it's very bad code, as manutd points out.
1) Illegal form of main() used
2) Made with a compiler at least 25 years old
3) Using functions that don't exist in today's compilers
4) Using headers that don't exist in most compilers
5) No comments make the code completely useless as a teaching tool

IMO, this does not qualify as a CODE Snippet.

It is nicely formatted though, but the indenting needs to be a tad more consistent.

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

As you loop through the equation, remember the position of each ( you see. When you see a ), extract everything between the ) and the last ( you saw. Replace these characters with SPACEs to clear out the extracted section. "Unremember" the ( location since it's no longer there. Continue through the equation until you reach the end.

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

With your lack of formatting I must be missing the for , do-while , or while statements that start your loop

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

// Also i wud be happy to ...

And we would be happy if you'd use CODE tags and format your code

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

We don't know where either, but there certainly is one missing. It all depends on what is part of your function and what isn't.

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

While you're googling, google for satire.

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

Compared to NetFlix commercials, Geico commercials are award-winning caliber.

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

Your formatting is bad.

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

I fixed up my code some and now the program runs, but it crashes after entering the rows and columns. Im not sure why, why is it crashing and not finding the number of steps?

It crashes? Then it doesn't run, does it? :icon_wink:
You should know by now that details are important -- what kind of crash?

void makeNextmove (int curRow , int curCol , int &newRow , int &newCol)
{
	int coin=rand()%4;
		if (coin==1)
			(newRow=curRow-1,newCol=curCol);
		if (coin==2)
			(newRow=curRow,newCol=curCol+1);
	return;
}

1) comma format is confusing. Use full statements.

void makeNextmove (int curRow , int curCol , int &newRow , int &newCol)
{
    int coin=rand()%4;
    if (coin==1)
    {
        newRow=curRow-1;
        newCol=curCol;
    }
    if (coin==2)
    {
        newRow=curRow;
        newCol=curCol+1;
    }
    return;
}

2) if curRow = rowsize-1 and you get 2, what value is newRow? Is that a valid position?

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

In general designate them private.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
  1. Use code tags.
  2. Is this a code snippet? You don't have it flagged as one.
  3. If not, what's the question?

Don't mention Code Snippet! They are posting enough Code Snippets already that we have to edit! :icon_twisted:

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

for(int x=2; x<(number/2); x++) Start a loop from 2 to number/2, incremented by 1
If number is 10, loop through 2,3,4, { while(number%x==0) Another loop -- when the remainder of number/x is zero exit the loop number/=x; Divide number/x giving a new number }

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

I personally think you are very confused. string record = "abcde\tfghij\tklmno\tpqrs" There are no \'s in this 22 character string, only TABs. Therefore this loop

while (record[counter] != '\\' && record[counter] <= length ) 
{
    counter++;
}

will run through the entire 22 character string.

You should at lease print out the value of counter just before if (counter> record.length()) { It will probably tell you a lot.

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

It seems to me you college would have all the answers you are asking. They will know what the major would be called. They will know their industry ranking. They will even be able to tell you what classes you would need to complete the major.

Maybe you should talk to them...

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

The problem, Dave, is the string is really string str = "abcde\\tfghi"; At least according to post #3

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

You start by choosing a language
Look you the for loop
Add code to support the loop

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

Oh, gotcha. Find the '\' (the escape) and the following character is the character.

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

Can anyone help me tweek my code. This program is supposed to get the day number 1 through 365 from the user and display the corresponding month and day. I'm getting so many errors I don't know how to start or really decipher the error in C++.

Gee, my psychic powers aren't working well today. I cannot read the errors from your screen nor mind. Sorry.

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

Didn't that work?

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

Don't output it.

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

Look up the function isalpha() and test each character after you read the line.

Also, see this about gets().
And see this about formatting. Yours is not very good.

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

Look up a bubble sort. That is the easiest sort to implement.

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

You open the files in main() , you don't check if they opened properly until you've called your function. Bad form. Open and check immediately. That way you don't waste time and confuse your brain cells later.

Then you use scanf("%s"...) which is dangerous. See this, then jump to Part 7.

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

Here's what I see:

std.open("std.txt");
   if(std.is_open())            // Why are you doing this?
   {                        
       std.seekg(0, ios::end ); // Jump to bottom of file
       fstd = std.tellg();  
   }
    
    // If open failed, why are you trying to read?
    std.read(st,fstd);    // You've jumped to the end of the file
    std >> st[n];         // -- there is nothing there to read
    n++;
    std.close();
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I must be forgetful. I thought I mentioned the Member Rules -- must be getting old. In any case, read the Member Rules. They will explain how not to ask a question and give ideas about what you need to provide.

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

when i try it to add i and compile the code i got errors and warnings. And when i try to run the program it gives me an abort message with red x on it.

Gee, since there are only about 2000 possible errors, all we can say is "you did it wrong." Would you care to point the problem?

Are there any good suggestion to where i can add the code safely/properly without getting any errors and warnings.

Considering where you did add it, either
1) No there
2) With the correct syntax
3) Both

Please keep in mind we are not psychic and not able to read your mind. Neither can we see what's on your screen. Therefore, to get help it is YOUR job to give us the details we need to understand your problem.

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

Hey everyone! this is my first post at this forum:P

We know. It's in the header with your name... ;)

Please go through and answer what question you can

Sure.

is anyone willing to help me?

Yes.

If you had actually asked some questions, this reply might be more useful. But it seems you didn't read the Member Rules as requested upon registering.

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

You have to deal with the array index and the loop index i separately.

Only increment the array index if -1 is not read.
If you see the -1, do not increment the array index.

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

bantex, even though jephthah comes tromping into your thread being condescending and belligerent, spouting derisions and opinions with no backing explanations, he is correct. He feels you are just supposed to trust him. Allow me to add the small bits of information he neglected to tell you:

get rid of that "gets" statement right now. replace it with "fgets"

Yes, gets() is a very ill-behaved function. Here's why.

and change your "void main" to "int main(void)" while youre at it, since that is sloppy practice.

It's not sloppy. It's wrong. See this.

and, really, "conio.h"? "clrscr()"?? getch()???

conio.h is not standard C. It is an extension to a select few compilers and when you come to rely on it, you will find all your code broken when you change to a different compiler. Best to stick with standard C headers and functions.

your teacher needs to be hit upside the head with a board.

I also agree with him here, too. Your instructor needs to get out of the 1980's and teach real C -- Standard C, and stop using a 25-year-old compiler because it's familiar.

jephthah commented: i'll trade give you my green for your red. +6
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Nice! Question. Why did you resurrect a two year old thread asking a question that has no real relation
1) the the thread itself?
2) to the language the forum is about?

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

I have to create a bst in which i have to add string values in the nodes..I have to display the no of nodes inserted each time..When I insert small string like..FA or B...i am getting the correct value in count[count is the variable which I have taken to count the number of nodes in bst]..But when I enter a larger string value like a2b3bergrk the count is not working properly...its intial value which is set to zero is changed to some garbage value..like 8543245 instead of 0.

Need to know the definition of the

  • string input variable
  • string variable in the node
  • value being set to 0
  • count value
  • node itself
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

In the Dev C++ documentation, what does it say about the gotoxy() function? What ate the parameters? What header is needed?

hi there, sorry but i don't really know about all these documentations, ...

Then how do you know how to use the compiler? You need to "know about all these documentations" to know what the compiler is capable of.

... but one thing I know and everyone is being talking about is that gotoxy is Borland function((

Yeah, I know, too. I wish he didn't bring it up because Borland is not Dev, and everything's now confused. Ignore all mention of Borland.

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

Is this me or does this look like C++

list<item_set> candidate_set;

Nope. Not just you. Please clarify, johndoe444

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

Why do people read one post and ignore all others? Maybe one or two of the others have some useful information or necessary questions...

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

I believe it's a non-standard BGI function from Borland's library. It's probably not going to be included with the Dev-C++ gcc.

That's why I asked dinamit875. He's using the compiler. :icon_wink: I already know about Borland. I don't know Dev well enough, though.

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

Please consider better formatting. You don't have to TAB into the next county. What happens when you have 5 nested loops? Your tabbing will have the inside loop indented about 120 spaces.

4 spaces is more than enough for each indent level...

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

Put the code in a separate cpp file as a function, create a header file that includes only the function prototype.

In the 'other' source file, include the header. Compile the two source files together and viola -- a dual-source program.

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

Why are you resurrecting a 6 year old thread as if you have something to add?

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

The themarval is blowing smoke. He seems to be asking completely unrelated questions to the task. Header files is a red herring and confusing everyone. Let's dissect the original post:

I'm taking an intro course to C++ and we're covering stack overload and how the library and linker come into play with programming.

What they learned in class. Does this in fact relate to the question or just fluff information?

I have a simple .cpp file called dataType.cpp. The code is as follows

int A;
int rtn;

int main()
{
rtn = dataType(A);
cout << rtn << "\n";
return rtn;
};

we're supposed to write a function that returns an integer. If the parameter is a long double return a value of 1, if its a double return a value of 2, a float should return a value of 3, an unsigned long integer should return a value of 4, long integer 5, unsigned integer 6, integer 7, unsigned short integer 8 etc.

There is the problem definition. Nothing about header files, linkers. just a straight forward programming problem about overloading a function.


Now the red herring starts:

Now......I believe that the header file is basically my function. But if my .cpp says to simply return a value - i guess I'm not sure what my header should say?? To me it seems as if the function already exists in the .cpp file?

Header file is a function? Obviously themarval doesn't really know what a header …