jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I think what's happening (based on some experimenting) is that the code is progressing much faster than the website is loading. Therefore there is no url in place(it's undefined since the site hasn't loaded) by the time execution gets to your if statement.
Check out the DocumentCompleted Event of the web browser control: http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.documentcompleted.aspx . You can find it by highlighting the web browser control, going over to properties on the right hand side, and double click the cell next to DocumentCompleted. Now do your url comparison within that method. For some odd reason when I tested it with a message box in the DocumentCompleted the box was being displayed twice but you should be able to find a way around that.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

WaltP did talk to you about the code formatting. Do you see how difficult it is to follow when it's spread to the right so much? Next piece that you put up you should adjust the spacing.

What I would do is put an if statement with each case (0 to 3) that "locks out" the moves that don't make sense. So if move right is passed a number along the right boundary it tells the user to select another move.
Or you could make that functionality part of the move right itself and have it return an integer value indicating success or failure and based upon that you can tell the user to re-enter.

Also, and maybe I'm thinking of the wrong game, but isn't there supposed to be a number missing and the user has to slide the tiles or pieces into an empty space to move them? That really restricts the movement.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Do you know how to draw random numbers with rand()? You need a "setup" function where you draw numbers between 0 and 15 and place them into an array 16 elements long checking to make sure the number you drew wasn't in the list already.

Where are you having problems with stuff going out of bounds?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Put in a cin.ignore() after line 16 and before line 21. Your excess '\n' from when you enter the integer remains in the stream and gets caught by the getline. getline figures it has a line and stops reading.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In order to place the string into the array of strings you must specify an index. E.g.,

cin >> stName[0]; //to write into the first string in the array
cout<<stName[0]<<endl;
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I know what you mean. I found this (it's in C# but can be converted to C++/CLI) to make a (File) Explorer setup in your program. It's fairly lengthy but if that's what you need you can probably whittle it down a bit.Strangely enough there's not a built in widget for this kind of thing you are describing, at least AFAIK.

My first thought was to just use a SaveFileDialog. It will show you what's there already and you can filter by extension and such. If your folder is a "downloads" you need to pick where to save something anyway, right?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Well it's more than it needs to be:

if (paintLitres - (int) paintLitres > 0.001)
     litresPaintReq = (int) paintLitres+1;
else
     litresPaintReq = (int) paintLitres;

You'll go back and look at yours 6 months from now and have to scratch your head for a minute.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm getting your point but unless you have a 250 line display you're not going to see it all at once. I don't believe there is any standard method for reducing the text size. That's why I was offering you the technique to pause the output every 50 lines (even for that you'd have to stretch the window from an "average" cmd prompt).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yeah, I get the idea. You can emulate ceil() by casting paintLitres to an int and subtracting that value from the paintLitres value. If that difference is greater than zero litresPaintReq = (int) paintLitres +1; .
Since this involves floating point and "0" becomes somewhat subjective, you should set a threshold for comparison so say if the difference between paintLitres and (int) paintLitres is greater than 0.001 then round up (since you can probably give or take a ml of paint).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

When the user clicks the button do you want a Save dialog box to pop up so they can name the file or what do you want to happen?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If your paintLitres has a decimal of less than 0.5 it's going to round "down" (really just truncate off the decimal). Try using the ceil() function ( #include <cmath> ).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

how can we put break or pause in the program.?

See post #2.

I don't know why your system is doing that? Are you running it within the "shell" of Turbo C or are you running it at a dos prompt? Beyond that I don't know. Is your instructor that bent on how your output appears on his screen? I'm certain he understands there are not 250 lines.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yeah give it a try. This will let you pause the screen. That way everything won't go flying by. Run your exe at a prompt to get a more accurate picture as I'm not sure (and I'm sure not gonna find out) what goes on when you run it in the shell of TC.

P.S. Also learn to use code tags. Very simple

[code]

/*code goes here*/ /*more code*/

[/code]

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Hey Narue!

Why can't I have groupies? I'm sure she'll be thrilled with the shout-out.

Anyway... look at line 36 in relation to your while loop. Walk yourself through a cycle or two of the loop, noting when the file gets closed.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can use the function getchar() to pause for the user to hit a key. You can use an if statement with the modulus (%) operator to set how many lines you want before the user is prompted.

For example 0 % 50 = 0, 50 % 50 = 0, 100 % 50 = 0.
See if you can come up with it.

P.S. To see where your prior output has gone you can scroll back in the cmd window. If you are using windows you can set the scrollback buffer by going to the system menu (upper left hand corner) of the cmd window, Properties, Layout tab, Screen Buffer Size and adjust the height.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
else return (n / (2 * n + 1)) + seriesFunc(n-1);

The first portion is being computed with integers, so you need to cast either the numerator or the denominator (or both) to a double.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

When you don't use braces to delineate your if/else groupings only the statement immediately after the if or else gets executed:

if(condition)
   This would get executed when condition was true
A statement here would cause an error when an else is present
else
   This would get executed if condition is false
   {
       The stuff in these braces would be executed if the condition was false because it is with 
        the "This would get executed" statement 3 lines before
   }
This statement would be totally on its own, not part of the if or the else

So now you see why your output on line 13 was executing regardless.

I don't have a good text recommendation for you. I used to like Kelley/Pohl "A Book on C" but it's getting a little outdated and might be a bit too dense for folks just starting out. Their book "C By Dissection" (meant for beginners) is not very effective IMO.

I'll chide you one more time about the formatting too. Read the article WaltP linked in Post #3 (it's written by some guy WaltP at another site, probably just a coincidence). It's definitely hard to match your braces up and what goes with what when everything is crammed up against the left hand side like that. If it's easier to read it's easier to help you.

Xufyan commented: great - xufyan +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

int nums[14],checknum[14],displaynum[14] is how you've declared your arrays, with 14 total elements. Your loop goes 0,1,2,...,14 which is 15 elements.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Are you compiling on *nix? If so you may need the -lm switch to get math.h properly.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

<deleted> Nevermind. Sorry.

See VVVVVVVVVVVVVVVV

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Well vmanes, that was a well-deserved semi truck driven through that garage sized hole in my knowledge :)

I do normally test these things. I went and tested to see what I was really thinking of and I guess that I made too much of a generalization from the stream problems resulting from combining cin and cin.getline. I had also misunderstood that the OP had been feeding 2 chars into the cin. Apologies to the OP.

Also thanks for the heads up on the Debug vs. Release behavior.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What's actually happening is something a bit different

cin >> ch1;
cin >> int1;

ch1 is a char so it holds 1 character. When you are typing in the character to go into this variable, you hit enter. Enter is a character which remains in the input stream and is processed by the cin >>int1; call which interprets it as "someone has pressed enter" so it skips the statement entirely without letting you enter an integer. The answer above about int1 being an uninitialized value is pretty much correct (though I believe it's more that the compiler sets aside an "empty" portion of the memory which could have any state and not so much that it assigns the memory an arbitrary value -- I may be inaccurate on that point).

P.S. You can eliminate that extra newline from the stream by placing a cin.ignore() between the 2 lines above.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

else if (randomNumber >= 31 && <= 59) is not valid syntax it must be else if (randomNumber >= 31 && randomNumber<= 59) . The same thing for line 34.

As an aside, you only need to call srand one time in your program.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

He didn't specify, but from another post I believe he is doing a CLR winforms and not an MFC application.

It would be:

comboBox1->SelectedItem  //The selected item (of type "object")
                                          //must be casted before using
comboBox1->SelectedIndex //The (0 based) index of the item
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I don't believe that you can call VectA.reserve() out in the middle of nowhere like that. I'm assuming this is a paraphrase of your code. Moving the reserve call to main() (after creating a main) I was able to get it to compile and give a size of 0.

Edit: Also make sure if you are compiling on the command line that you present them in the order globals.cpp and then main.cpp on the list of files.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

a is a char and " " is considered a string. When comparing something with a char, use the ' ' (single quotes).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The whole idea of the overloaded operator is you can now say something like if(Rational1 < Rational2) and it makes sense to the compiler because it has an overloaded operator to tell it how to perform the operation.

However, you have to implement it in your source file like you did on lines 90 to 98 above. Tetron's method of having one parameter member functions would work too but you seem to be more comfortable this way. You can then borrow the formula that you have posted on your latest post in red and so in that case

bool operator <(Rational &Fraction1, Rational &Fraction2)
{
	return ((Fraction1.numerator1 * Fraction2.denominator2) < (Fraction1.denominator2 * Fraction2.numerator2));
}

since we want a true or false value and the ordinary use of the < gives us true if the numerator-denominator products have this relationship. Therefore, reducing the problem to comparing integers (which is something the compiler knows how to do) helps us to compare the objects. Also, hint, the > operator can make use of this method.

On a peripheral note, your tests function above is meaningless as you have set it up. Mathematically a rational number is any that can be expressed as the ratio of 2 integers, with the denominator not equal to 0.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Here's a fairly lucid explanation for static vs dynamic.. This has good examples.

Another article that covers all 4 in an understandable way.

How come you gave a link for google? LOL I'd been searching all over for it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

while (newIsTherePtr->item!=item) needs another condition to ensure you don't run right off the end of the list (e.g., && it with newIsTherePtr->next !=NULL or however you designate the end of your list)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

if ( x > 3 ) x = 0; When will x ever actually reach 10?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See, I think you are running into problems because you're supposed to have one rational number per object. Then if you are comparing two rational numbers it will actually mean something.

You have sort of the right idea but you want to compare the numerator and denominator of the object in question to another one (e.g., 1/2 or 1/5 which is bigger, by your definition neither is). Otherwise you can make a two parameter version be a friend function to your class but I'm not sure if that's in line with your objectives.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What does the code look like now and what does your input file look like?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use your getline statement to drive a while loop (I'm assuming you don't want the blanks you were just finding a way around them)

while(std::getline(cin,command,'\n'))
{
  //Other statements here
}

When there's no more input the loop should exit. Make sure that in your file you don't have extra blank lines at the end.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

the [] only work if string is defined

Yep, just came to the same conclusion.

I think what you meant Tetron was to substitute output +=alpha[r] for the output[r] = alpha[t] .

Another option would be to dynamically allocate a char array but that wouldn't be able to take into account repeats in the letters of key.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

no i diddnt put getch(). What does that do?

Unfortunately getch is part of a nonstandard library for console input. A portable solution would be to put cin.get() in the same spot.

iam using visual c++ 6.0 on windows 7 64bit. so could it be compatability issues thats causing it to crash?

This is not outside the realm of possibilities. Try downloading the 2008 express edition as VC6 is almost 12 years old.

thanks for the reply jonsca but i forgot to mention that i need to do other things with the array afterwards. i was just outputting it in this instance for testing purposes

Gotcha. I'll try running your code and see what the outcome is.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There doesn't seem to be any requirement to keep an output array, so it may not be necessary to shift the arrays all around if you are just outputting the results to screen. Just say if alpha !='0' then output the character.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're still missing out on how the objects should be used. Your object contains a numerator and denominator and a way to print itself. Therefore you should have

Rational myrationalnumber;
myrationalnumber.setNumerator(2);
myrationalnumber.setDenominator(5);
myrationalnumber.showfraction();

which would print out 2/5
Then you can make another object for the second rational number.

Your class defines what the object has for members and how it behaves. Each object carries around its own numerator and its denominator. It knows how to print itself, therefore you don't need to pass it anything to print as it has access to its own member variables.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I believe the objective of the assignment is to have one instance of the rational class which contains both the numerator and denominator for the first number and another instance that contains both numerator and denominator for the second number.

As other posters have pointed out, your setter functions are potentially incorrect also. It is customary to have:

void Rational::setNumerator(int numerator)
{ //set the private variable by the value being passed in
     Numerator1 = numerator; //following the name of the private 
                                         //variable from your class
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The OP wants to print the letters not used in the original "key" after they have output said key (I think the OP left an h in the extra letters of the example which was confusing).

I would use a string like lotrsimp said, but in your alpha collection write a number or other character over the used letters so if your key were "abd" your alpha string would look like "00c0efghijklmnopqrstuvwxyz"
A simple if statement gets you the chars you want.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Being from the same "generation" of members I've noticed this too. There are others in the same boat.

Give this a read: http://www.daniweb.com/forums/thread229580.html

Since this has been an issue of great debate I'm persuaded to think that it makes sense this way over the long haul.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What would the value of strlen() return in that case?

Argh... Yup, brain fart.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

That seems reasonable, but what if the buffer is 20 characters and the user only enters 4 and hits enter?

WaltP commented: Are you being silly, or are you having a brain fart? ;o) +11
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

(I don't remember if C uses .size or .length for arrays..).

Neither lol.

int i;
for (i = 0;array[i] !='\0';i++)
{ 
    if(array[i] =='\n')
       array[i] = '\0';
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Did you mean to post this in CompSci?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

IMO, you could have a system where posts on threads over 3 months old require moderator permission. It's more work in the short term but having to take the time to approve 5 threads rather than having to close 20 for the usual spam,"I have a totally unrelated problem but this thread looked good or had a lot of posts on it" etc. it would end up saving time. Sure it takes a little bit of control out of the hands of the community but if that's the chief complaint then why have moderators in the first place?

jephthah commented: word +0
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
declares an array of strings    
    string item_name[number_of_items];
    
    cout << "How many items does the customer have? \n";
    cin >> number_of_items;

When specifying the size of an array in the declaration like that on line 22, the value of number_of_items must be known at compile time (unless you have certain language extensions on when you are compiling, but that runs the risk of your code being non-standard).
You have double trouble because even if it were legal, you declare the array to be that size before the user gets to input a value.

Your best bet is to prompt the user for input but then create the array dynamically. So scratch line 22 and around 26 put in a: string * item_name = new string[current_input_number]; Check your for loops also: remember that arrays are 0 based.

EDIT: Sorry I stole the thunder of your teaching moment WaltP

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Put in a cin.get(); in between lines 9 and 10. It's along the same lines but it's also nice and standard.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You use it in a similar way to gets except you specify the maximum size of the char array you are reading into.
Take line 33:

fgets(Stud[i].Name,sizeof(Stud[i].Name),stdin);
(or you could put in 20 for the sizeof(Stud[i].Name) portion)
(last parameter is there in case you wanted to get input from a file, so you just need stdin to get it from the input stream)

Just be aware that fgets will take in a '\n' character into the string/char arr when you press enter, so you may have to step through your char arrays and substitute a '\0' for the '\n' (fgets will append a '\0' to the end of the input anyway but this way you terminate it at the proper point).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Are you using Windows or *nix? windows.h has a sleep() function.

See this thread about ways to do it with the ctime header:http://www.daniweb.com/forums/thread233015.html


I know you're not asking for help on this part, but you should reform your goto into a do/while loop. It's a lot easier to follow that way.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're not the only one (by a long shot) that has that situation. I know you can't do anything about it, I was just giving you a hard time.