jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

#include <time.h> and you should already have stdlib because of rand(). At the top at some point before line 18 call srand((unsigned)time(0)); to seed the random number generator using the current time (and converts that value to one acceptable to srand).

A couple of little things: main() should explicitly return an int, so mark it as int main(void) and put a return 0; at the end of your code (before the last brace of main). Also, in lines 6-11 you can use the characters (e.g., 'A' ) to make things easier to read so you won't have to remember.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Hint: check the line before it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

That was your code that I had pasted in. I was just trying to narrow down the window for you to find the spot for it. You've got j in the right spot now. Use it to index your newstr array, so newstr[j] instead of i. Trace a sample run through by hand (or with your debugger) and see what the results are.

restrictment commented: Thanks a bunch! +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're calling computeAverage recursively from itself on line 44. It's going to keep going and going because there's not base case (stopping condition) for the recursion. I don't think you meant to do that anyway. Maybe you meant it to be a computeSum helper function because what you have there doesn't make sense.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
int j;//my addition
while (str[i])
  {
    if (ispunct(str[i])==0) 
	{
	newstr[i]=str[i];
	}
    i++; //this is keeping track of str
  }

When in here do we know, ok we've got a non-punctuation character and can increment the j counter? Where can we be sure of that? So j is the counter for newstr which we would increment when we were sure of having a non-punctuation character to copy in.
Again, say we have 0 thru 6, we want to copy this into another array and we keep track of that number of items copied over:
[i|j|k] so we have 0 thru 2, and we skip the period so then we have [i|j|k|m|n|o] and we knew to put m in at position 3 solely because we kept track of it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your parameters of your prototype don't match the parameters of your function definition. You don't need the x,y,z that's going to be passed in,the function doesn't care about that, you need something like line 39.

However, unlike 39 since it's a prototype you can omit the Array word, but leave in the int []). The prototype prepares the compiler for what's to come later so you need to tell it my function computeAverage has parameters of double and const int in that order. So you've confused it by giving it a prototype with 4 parameters rather than 2.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If newstr and str share the same i index, lets say position 3 of str was a period. What happens with index 3 of newstr? It'll be a gap you'll be (almost) back to your original problem.

<snip>


You need a separate index for the newstr array.

Declare an integer j (or call it counter2 or any number of things). You need to increment j every time you get a "good"(non-punctuation) character so that you know what the next slot in newstr is. Once you've hit some spaces j wouldn't be equal to i but in your code you assume they'll match up. If I'm photocopying a bunch of sheets and passing them to you to file but I'm skipping the blank sheets, how will you know in which slot to place them. I pass you sheets 0-3, skip over 4, and now I pass you sheet 5. What slot is it going into? not 5, but 4 on your side. You would keep your own count separate.

You're so close I wouldn't give up at this point.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

One other thing, might be an issue:

The exponent on a variable in a term is called the degree of that variable in that term, the degree of the term is the sum of the degrees of the variables in that term, and the degree of a polynomial is the largest degree of any one term.

According to the definition you might need to take in another term so a polynomial of degree 2 will actually have 3 members (of course two of them could be 0). I believe I'm reading/remembering that correctly.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If newstr and str share the same i index, lets say position 3 of str was a period. What happens with index 3 of newstr? It'll be a gap you'll be (almost) back to your original problem.

From Mr. P (my emphasis added):

2) increment indNew for every non-punctuation character.
3) increment indOrig for every character.

You need a separate index for the newstr array.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What have you tried so far? Have you tried out an example with paper and pencil to get the thought process (which makes it much easier to code)?

Also please see this:
http://www.daniweb.com/forums/announcement8-2.html

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

So now create a new char array and copy all the non-spaces over (you could do the copying in combination with the first step if you copy all the non-punctuation over at that point). You know the new array will be less than or equal to the old one in size.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The extra '\n' from where you take in the number and press enter gets stuck in the input stream and carries down to your other prompt causing the wrong instruction error to come up (since '\n' !='y').

Here's a couple of tutorials to get you through the problem.
Particularly read the section on fgets/sscanf for your "rows" input.
http://www.daniweb.com/tutorials/tutorial45806.html
In this one read the getchar part and try to adopt it to your code.
http://www.gidnetwork.com/b-60.html

In a situation like you have here it can't hurt to initialize ch to 'y' when you declare it. As it was before the program was skipping over the loop completely.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

gets(String) ;

Don't recommend the use of gets. It can take input until the cows come home and tries to write it all to that array--> overrun. Use fgets instead.

Salem commented: Yes! +19
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Type "path" (no quotes) at the prompt that you are using. Make sure that your bcc directory is actually there. Otherwise you may have to write a batch file that sets these environment variables and run it each time you open up a prompt (you can automate this by creating a shortcut to something like %COMSPEC% /k "C:\Qt\4.4.3\bin\qtvars.bat" (this is an example from a prompt that Qt sets up for compilation).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Does this link help? (add your Borland directory to the path)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I attached the test program that I used. Even with the character array in the struct it swaps things okay. Try yours in isolation from your program to gauge for sure.

EDIT: I think our posts crossed. I'll take another look at your current code.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
void swap(Record a, Record b)
{
        Record temp = a;
	a = b;
	b = temp;
}

is not swapping the structs (as copies are being made). Try passing them by reference swap(Record & a,Record & b) or by pointer.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Check out the functions in ctype.h (include it as <cctype>). It has an ispunct() function which you could use as you're moving through your array. See this for a reference to all the functions in that header.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Remove all the stuff related to gs_A,B,C,D. You don't need them. You are passing in the thresholds for the grades, so use them.
If I were to say, ok, answer in terms of s1, what is the highest grade acceptable for a B? What is the lowest grade (in terms of s1) for an A. Do the same for s2,s3,s4 with the other ranges. Keep your function the way it was and translate your hard coded values into ones in terms of s1 through s4.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In that thread you specified, (I believe) Narue was saying that it was not a legal specifier for use with printf. That is the correct format specifier for a double in scanf. I thought she gave an explanation for that asymmetry at one point but I may be thinking of something else.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What was the old way that you were using? I don't think there's anything wrong with the way you are reading input in this case. You could make the coef be a dynamically allocated array so it doesn't have to be set at 11.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Scroll down towards the bottom of the page until you hit the Tags section (in green) move one line up from that (next to the gold "Reply to this thread" button). It says Mark as Solved.

xavier there's no reason to jump on a thread you hadn't posted on before just to say that.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Dereference s before you try to get the c_str() method: c = (*s).c_str(); since s is a pointer to string not a string. Or c=s->c_str(); will work too I just thought the other form was more illustrative for your benefit.

Also, strlen won't give you the length of the std::string, use s->length() (same need to dereference) instead-- unless you meant to take strlen of c instead.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

OP seems to have record being passed in as a char* . Shouldn't it pass in as struct PATIENT * record ?

tux4life commented: Exactly :) +8
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try it with numbers first if you are stuck:
1
232
34543
Then figure out how to translate from the numbers to the letters of the alphabet. Here's a hint:http://web.cs.mun.ca/~michael/c/ascii-table.html

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What have you tried so far?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you're using it just within your Form class declare it as a public private or protected member of that class. Start from public ref class Form1 : public System::Windows::Forms::Form and scroll down you'll hit an area where your buttons, webbrowsers, etc. are declared. Put it somewhere in there or where you will remember about it.

If you need to share it across forms possibly declare it outside of the class (like under the using directives) but with that comes all of the hazards, pitfalls, and gotchas associated with global variables (the solution above isn't much better but it fits in the with Form.h "culture").

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There's a guy with 3 legs =)

I thought his associate was attempting to moon the Google vehicle as it went by but missed the chance. Does anyone know what these cars look like? I've never seen one.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Frank Fontana? From Murphy Brown (sorry that's the first thing I thought of when I read that)?

Wager a guess as to who's getting an alarm system as a very late holiday gift?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I might think of it this way: For your second example you have 3/4 chance it will roll 2 and 1/4 chance of rolling a 6.
For this specific case, get a random number between 0 and 4(exclusive of 4). If you pick 0,1, or2, you've rolled 2 and if you pick 3 you've rolled 6 (or intersperse the value you want to pick to roll 6 among the lower values to make it potentially more "random"(a loaded word for your loaded dice)).
Have the user enter in the probabilities for the different numbers in ratios or else it will make more trouble for you.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need something like this in your moveup (for example)

if(board[i] == 0 && i !=0 && etc etc)
 {  /*for which other positions is this invalid */
     swap(&board[i], &board[i-4]);
     break;
 }
  else
      printf("Invalid move\n");
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

Also you must include "stdlib.h" in your source

For what function?

Also, please don't just give the OP the corrected code, help them arrive at it.

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

Line 16, try initializing part_sum and tot_sum to 0.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Right, I would certainly agree. I was just looking at the if and the else branches both calling the recursive function, but you're 1 step ahead MrP.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

So does getline only work with the following:

getline(cin, StrVariable);

It threw errors when I first put it but seemed to work when I switched it to a string (instead of char).

There are two different versions.

This one works with C-strings (char *) and is a method of the stream object (i.e., invoked as cin.getline(mystring,capacity) ).
http://www.cplusplus.com/reference/iostream/istream/getline/

This one works with std::strings and takes the stream object as an argument (i.e.,invoked as getline(cin,mystring) )
http://www.cplusplus.com/reference/string/getline/

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to place a return; (with no value) statement somewhere in your recursive function otherwise it will keep going on and on. Think about what your variable "value" will be when you run out of digits and use that as your base case.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In trying to help this OP I've tried to implement it using:

void storeValue(int value,int *&list,int & n)
{
	int * temp = new int[n+1];
  ... //if this is correct I don't want to steal all the fun
  ... //with the stuff in here but I can post if nec.
      
        //delete list
       //assigning temp back to list
        //delete temp
}

(and I tried it with ** too -- which is what I think lotrsimp was getting at so apologies) but despite all of the careful passing the array it is gone once it gets back to main. I know I'm making some sort of fundamental error here but I cannot figure it out for the life of me. To the OP thanks for letting me side track things a bit but I think this will point you towards a solution.

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

Check out this thread. It's got how to turn it off and on too (beyond what you need I know) but the detection of it is simple. I don't know anything about writing services but if you were to make a regular form and run it on a timer (so check the status every N milliseconds) it would probably do the job. I'm not sure about the focus aspect either. It sounds like a neat little widget.

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.