jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Or you can access that directly from ts.Days in the above code.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Using 2 datetime pickers you can get the timespan between them

TimeSpan ts = dateTimePicker2.Value - dateTimePicker1.Value;
            MessageBox.Show(ts.ToString());

To do what you're suggesting would probably take the user putting in one of them to the DTP, hitting a button to lock the value into one DateTime object, choosing a new date then hitting the button again (or something to that effect).
Either way the timespan is the way to measure the difference and then you can take the timespan apart based on seconds, minutes, total seconds, etc.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What were the specific warnings you got?

Please use the code tags when posting the code. You're not getting n and k from anywhere so they are undefined. Either prompt the user for them or declare them like int n=5,k=3;. You don't need that first C(n,k); in there on line 15 or so, as your function is being evaluated as part of the statement with cout.

Other little things, you don't need to include <algorithm> since you're not using any of its methods. Instead of System("Pause"); use cin.get(). System as call has to halt the program, bring up the OS, run the command, and then bring up your program again. Plus cin.get is portable.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In main, declare 2 int variables n and k. Get input from the user using cin or initialize them when you declare them.
Use a statement like cout << C(n,k)<<endl; which will call your function and output the results returned from the function. Your recursion will take care of all the subsequent calls the main program just sits and waits for the return.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I've tested it and it seems to come out ok (against a site like http://www.ohrt.com/odds/binomial.php). What trouble are you having with it?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
string text = textBox1.Text;
string[] numbers = text.Split(',');
string delimiter = ","; //or leave out the , and put a space
string test = "";
for(int i = start;i<=end;i++) //to include the right endpoint
{
       test += numbers[i];  //or you can parse your numbers into ints
       if (i !=end)
               test+=delimiter;     
       textBox2.Text = test;
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

When going through your loop after entering in the physician's name

for( i=0;i<n;i++)
{
	cout<<"\nEnter physician "<<i+1 <<" name :";
	cin>>phy_name[i];

it's trying to write the entire name to phyname which is only one character. Consequently the extra characters remain in the stream, writing into the next set of variables and so on.

Using strings would be the best idea (std::string). However, sure I know it's probably your assignment to use char arrays, so look into a function like getline() (used as cin.getline(chararrayname,capacity); see this for a reference) but you'll need to cin.ignore() some characters that are left over in the stream after the getline (especially if you are still using cin >> for your ints and such).

I knew I had heard that somewhere before. You've tried twice shove this onto our plate but the thing is you need to be proactive in changing your program. I've told you that using cin >> to write 1 character (which is what phy_name is!) you will get 1 character. So if you type in a name where 1 character is supposed to go you're going to get a major overflow that affects the subsequent calls to cin.

If you have trouble with cin.getline() try the C function fgets (need to include <cstdio>)http://www.cplusplus.com/reference/clibrary/cstdio/fgets/, but I'm not honestly sure how well it behaves with cin >>

See http://augustcouncil.com/~tgibson/tutorial/iotips.html#problems for the issues I spoke of with cin.getline() and cin together.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Console.WriteLine(prime.ToString() + " - Prime"); You left your C# hat on... :) Only kidding.

He/She also needs to check the numbers to see if they are palindromes too. OP was trying to just check the first and last digits but for a 4+ digit number this will probably yield incorrect results. If possible use a stringstream to parse the number and work your way to the middle of the string (or work your way through the number by division and compare the digits that way--which might get tricky for large numbers-- if you have an upper bound you could create an array with length # of digits).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Sounds like you need regular expressions.
Here's a succinct tutorial I came across. They are toting some product or something but it has a few good examples of what you might need towards the bottom of the page.
http://www.radsoftware.com.au/articles/regexlearnsyntax.aspx

Here's the MSDN page that gives a couple of oversimplified examples but that should give you some of the syntax.
http://msdn.microsoft.com/en-us/library/ms228595(VS.80).aspx

I would imagine there's some linguistics material out there that deals with the kind of statistical processing of which you speak but it might be overkill for this.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Let's make sure this is clear: no one is going to give you the code. We've given you a few suggestions as to how you should proceed with the betting part of the code. Salem is right, this is a toy problem designed for early undergraduate students. Make an attempt at writing the betting portion and then we might be willing to talk about it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

you can use a variant of the using statement using std::cout; using std::cin; thereby qualifying those method names only.

I realize that I might have been confusing. If you put using std::cout; once underneath your #include (though it could be anywhere) you're covered for the remainder of the program in being able to use cout without the std::. Do the same for any members of the std:: namespace that you need. The way you did it is totally fine and is in fact preferred by a lot of people, but if you're just starting out it can be painful.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It has a variant Substring(startindex, length) . If you're going to do it based on index of the number alone you could copy it into a new string without the commas.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
newtextbox.Text = oldtextbox.Text.Substring(12);

The 12 accounts for the commas in the string. Substring(12) grabs all characters (including) 12 and beyond.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Don't use goto. Use a loop instead. This way you can put in an exit option. When getting input like you are use a do/while loop so that you can test for whether you should exit the loop after you've gone through one cycle.

Your function names leave a bit to be desired and the abbreviated names seem to be opposite of what they should be. There's no need to skimp on characters especially for readability. It's the old 6 month rule, could you come back in 6 months and know what exactly they did?
(also why comments are a great idea)

Skip all these sleep calls. By and large the places you have them wouldn't require it anyway. Needing the Windows functions adds a tremendous amount of overhead to your application.

Your functions return an int, but you should actually return the value you got for the conversion to the main program so their return type should be double. When returning to main() use the return (your double variable here); keyword, don't call main again. Skip the "would you like to go back to main" portion of it and just have a return statement (no system("pause") in these functions either).

Your system("pause") in your main program will never see the light of day as you return 0, and you've exited your program. But skip it anyway because (and you had the right idea with the getchar) use cin.get() to have the user press a …

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I haven't managed to cobble together a solution just yet, but essentially what you have to do it get the total length of each line by converting your ints to strings (via stringstreams), geting the length for each line (stored in a vector, say) finding the maximum length. Then you can iterate through the mmap this time to output and put in the number of spaces difference between maxstring and the length on the current line.

EDIT: Your cout.width() was causing me some trouble so I changed it to a setw(). Not sure if that will make any difference

#include<sstream>
#include <iomanip>   //add these to your existing headers
#include <vector>

 //all this replacing your line int maxStringSize=max_element ... and below

stringstream ss;
int maxlength = -1;
vector<int> linelength;
 
for (it=(mymm.begin()); it!=(mymm.end()); it++){
  
   ss.clear();
   ss.str(""); 
   ss <<it->second;
   linelength.push_back(it->first.length()+ss.str().length());
   if(linelength[linelength.size()-1] > maxlength)
	   maxlength = linelength[linelength.size()-1];
  
 }


setw(maxlength);

for (it = mymm.begin(),vecindex = 0;it!=mymm.end() && vecindex<linelength.size()<;it++,vecindex++){
	 
	 for (int i = 0;i<maxlength-linelength[vecindex];i++)
		cout <<" ";
	 cout<<it->first<<"-"<<it->second<<endl;
	vecindex++;
 }

My usual caveat: there's probably a better way to do it. The second for loop isn't very pretty. You get the idea though.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

So just to clarify in your example the output should look like:

<space><space>y12-100<space> z1234-250<space><space>  x1adsf-5
<space><space>y12-150<space> z1234-300
 <space><space>y12-200

this? (with width = 8)

I'm just a tad confused...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Repost the code please.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

can I use this one,

Only if you know exactly how many records there are. You can't just use the ifstream object alone as your loop condition the way you have it.
Try it with the arrays and post back (with code tags as my provision still stands).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Please use the code tags

if (guess < randomNumber) // If guess is < than the random number, display
           cout << "Your guess was too low\n\n";

if (guess > randomNumber) // If guess is > than the random number, display
           cout << "Your guess was too high\n\n";

You did not read the specification too well. It says they want the output to match what they have and there is nothing about higher/lower there.

The do/while is a step in the right direction. Except you should read the conditions they lay out for you about what happens when the balance is zero or the user enters a zero bet.

The rest is a bunch of if statements. You need to account for a user trying to bet more than they have and trying to bet a negative number. Use two double (or float if you prefer) variables balance and bet. Adjust balance from bet according to the specification they gave you.

I think you need to sit down with it and spend some time. Break it down into pieces. You've already got a lot of the I/O down. Give it a genuine go and post back with any problems.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm not going to help you any further until you use the code tags(use the edit button to edit your post). Use them as follows:

[code]

#include ... etc.

[/code]
Or highlight your code and hit the

button in the menu bar of the editing area

EDIT: You were already over the time limit I think.[code]
button in the menu bar of the editing area

EDIT: You were already over the time limit I think.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Just step through your char array:

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

You're very welcome, glad to hear it!

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Firstly, please learn to use code tags

EmpRec>>Ename>>emp_rec>>no;

This is reading exactly one line from your text file and stopping. The expression you have in your while loop condition isn't actually doing anytihng. Put mpRec>>Ename as your while loop condition

while(EmpRec >>Ename)
{
      EmpRec >> emp_rec>>no; //you might be able to jam all 
             //this into the loop condition but 
             //it's a bit easier to read
}

Prompt the user for input before you go into the while loop, the way you have it the user can keep entering a new number as each record is read.
If your data you are checking is of the form 2010-0001 how do you suppose your int is going to hold the dash? Much better to make it a string.
I'm sure there'll be other things that come up, but this is something to go on for now.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I dug this up :http://mail.python.org/pipermail/python-win32/2006-July/004825.html it's about win32 functions in Python but it refers the poster to the PIDDSI instead of the PIDSI constants -- hopefully that makes some sense to you because I'm out a tad of my purview here. It says in the post about PIDDSI_CATEGORY being the same as PIDSI_TITLE but that doesn't seem to make much sense.
Anyway it's something to go on...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I was able to get it to work with the code you provided (see screenshot). I'm not sure what Read-Only would have to do with it in this case (that would allow your textbox to work as a display and not as a data entry point). Is there anything else in your code that might be blocking that code from running?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I couldn't figure it out either initially but he means when you open that same Properties window but for example with a Word document. You get all those fields in that context.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Check this out(using Windows Management Instrumentation, WMI). I think it's what you are looking for but it's a Win32 API call so it involves using the P/Invoke technique (in which I am not versed).

EDIT: Using that relies on this which isn't implemented (??) in the WMI. Wish I could have been more help but do some searches with WMI and your requirements for your code see if you can come up with anything related that you can incorporate.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's two different people, that's why. Bokac piggybacked on the original thread (which he probably shouldn't have).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Are you using Mono? I couldn't figure out what you meant by the red box either. I has assumed you were using VC#...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Select all the items on your form (or select them in groups if you don't want the same settings for all of them). Go over and click on the properties tab under Solution Explorer (if you can't see it, go to View/Properties Window). Go to the margin setting. Change as you see fit (can change any and all sides)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you post a small portion of your code so I can try and run it?

for IComparer you need a class (can be within the same namespace, not sure if that's what should be done with it though):

Say you have a class Person that has a public member variable of type int named year of birth and you wanted to use this as your key.

public class PersonComparer : IComparer<Person>
{  //don't select IComparable which is something a bit different
    //see the article below

    //Now normally with ints, we arrange them from highest to lowest
//but we want our sort by age, so we reverse the usual scheme for 
//returning 1 if the first value is greater than the second one, or if they 
//are equal and -1 if first is less than the second

public int Compare(Person A,Person B)  //must be compare as that's
//what the interface dictates
{
           if(A.Year < B.Year)   
                  return 1;
          
           if(A.Year > B.Year)
                   return -1;
           else
                    return 0;

}
}

Then back in your program where you defined your list:

PersonComparer pc = new PersonComparer(); //for obj1
SortedList<obj 1,obj 2> personlist = new SortedList<obj1,obj2> (pc);

Excellent ref with some more examples:
http://support.microsoft.com/kb/320727

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I can't make the function of type void

If a function has a return value you don't have to cout it.

In your case you can either call it like lonelyday proposed square(side); which essentially ignores the return value completely
or you could say

if(square(side) == 0)
       cout<<"Success!"<<endl;

which implicitly calls the function when it tests the == 0 relationship.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Make your arrays 2D, with the number of names (or doctor names, patient names) in the first dimension and the max number of chars in the name for the second dimension.
Step through them using the first dimension and write into them with a getline with the first parameter being the array name (names indicating the ith array of 80 chars) and the second being the length of the character array.
Here's an example:

char names[3][80];

	for (int i = 0;i<3;i++)
	{
		cout <<"Enter a name:"<<endl;
		cin.getline(names[i],80);
		
	}

As for the arrays with int values, I would honestly change them to char arrays because a) You're not doing any arithmetic with them and b) It will make life easier with using the getlines for everything.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

A few hints:
1.) int square(int side, int i); is a function prototype. It should not be placed in main()
2.) function parameters are used to convey information between different methods. what information is i bringing into the square() method?
3.) grab a pencil and paper and go through your loop step by step for say side = 3, read through the instructions and draw what the program output is. You'll find at least one of your errors quickly.
4.) Where is the zero co ming from on the display? What are some of the options for the return type of a function? Do you need to cout for everything?

tux4life commented: Good hints :) +6
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try it as template <class E> typename LinkedList<E>::node * LinkedList<E>::getNode(const E &item) since I believe the situation is equivalent (or at least parallel to) this thread.

i'm sorry but i don't understand what you mean by

No, not a problem at all. I just meant that classically people put declarations, defines, etc. in the header file and leave the implementation to a separate .cpp file whereas with templates all of that (declarations, definitions, etc) together has to get lumped in the same .h file with almost all compilers.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Are your indicies of a type that have the ability to be directly compared? (like ints or strings)?

If not you must write an IComparer<your_index_object> method and pass it into the constructor of the sorted list.

Here's the MSDN for sorted list.
http://msdn.microsoft.com/en-us/library/system.collections.sortedlist.aspx

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Replace line 141 with those two lines. No, it has nothing to do with the preprocessor. Your function findGrade is void, it returns nothing. If your function returned an int, you could say afile << findGrade(etc.); there would be a value coming back to send into the output stream.

However, all is not lost because you are sending a char array grade[] into your function which will (effectively) come back out "knowing" the answer(in reality the address is being passed in via a pointer and so any further instances of it are changed since they point to the same item).
This char array is something that afile can handle, so it outputs it to your file. Think of afile almost as a fancy cout that sends the data to your file instead of the screen.

What is not working about it? Does it compile? Is it giving you weird results in the datafile?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You get a compiler error because the return type of your function is void (therefore no object to pass to cout)

Since you are passing grade by pointer into the findGrade method, you should call the function first by itself, after that grade will have changed and you can output your array of characters.

findGrade (marks, char grade [MAX]);
afile << "Grade " << grade << endl;
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

get_player_move(); on line 55, you're making a recursive call (calling a function within itself) which is ok in some circumstances but in this case it's going "infinitely" until the stack overflows and it crashes. Try to rework that section, you can probably put a while loop within the other while loop that calls the function until it returns a boolean:

while(get_player_move());   //in main()

bool get_player_move(void)
{
  int x,y;
   cout<<"\nEnter X,Y coordinates for your move: ";
   cin>>x>>y;
   x--;
   y--;
   if (matrix[x][y]=='X') //this should be if it's equal to X
  {
      cout<<"\nInvalid move,TRY again";
      return false;//get_player_move();
   }

   else 
  {
	matrix[x][y]='X';
	return true;
  }
}

This may not be the exact thing we want but this will take care of the infinite recursion. We will need to revisit the do while loop in main since I think that's causing problems too.

Also: line 85 is a typo cout<<matrix[t][0]<<matrix[t][1]<<matrix[t][2];

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I got it to run correctly

Cool

I had to add the goto statement back in my code

As an "extra credit" just for yourself try to see if you can write it without using one :)

Anyway, you worked hard on it so I hope it goes well. Post back if you have any problems.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

if (matrix[x][y]!='you have choosen the worng letter') What is that? ' ' surround single characters, not strings. How could your matrix value ever be equal to that?

Why don't you check if it's equal to 'x'?

Also:

if (matrix[i][0]==matrix[i][1]&&matrix[i][0])
is not doing what you think 
for all those if statements you need  (for example)
if(matrix[i][0] == matrix[i][1] && matrix[i][1] == matrix[i][2] && matrix[i][0] == matrix[i][2])
Then you have a win
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

textBox1.Enabled = !checkBox1.Checked;
(using exclamation point)
Try it like that for the effect that you want.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Like I said, it's really outside my purview. With "a bunch of lines of code" you could send a man into space but you need some type of API from which to springboard as there is nothing in the standard library for this. The Win32API has some methods which people have put wrappers around http://www.codeproject.com/KB/audio-video/midiwrapper.aspx. Again, I can only guess. You have to weigh your own ability level with your goals for the project and decide how much to learn.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I found a freeware app that did many of the things you want, but there's no source that I could see.

Did you run across http://www.harmony-central.com/MIDI/dev.html in your travels? Some of the kits seem outdated but you can probably find some good stuff still, esp if you are running Linux.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I don't think anyone is shunning you, I think it's just a highly specialized topic. I'm not in the music arena at all but I'm sure there are APIs out there, though they may be specific to whatever sound card you have and the like. It couldn't hurt to elaborate on what you mean by drum software, but it still may get no results...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

When going through your loop after entering in the physician's name

for( i=0;i<n;i++)
		{
			cout<<"\nEnter physician "<<i+1 <<" name :";
			cin>>phy_name[i];

it's trying to write the entire name to phyname which is only one character. Consequently the extra characters remain in the stream, writing into the next set of variables and so on.

Using strings would be the best idea (std::string). However, sure I know it's probably your assignment to use char arrays, so look into a function like getline() (used as cin.getline(chararrayname,capacity); see this for a reference) but you'll need to cin.ignore() some characters that are left over in the stream after the getline (especially if you are still using cin >> for your ints and such).

Ancient Dragon commented: good answer :) +25
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No prob. Mess around with it for awhile and post back if you have questions.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Check out this great article: http://ondotnet.com/pub/a/dotnet/2002/02/11/csharp_traps.html

in the article: "...because finalization is nondeterministic (meaning you can’t control when the garbage collector will run)..."

Dispose() can be used for any and all cleanup required but the garbage collector will gather the object and call it's destructor (thus finalizing the job).

I would say unless you are noticing via a profiler that the memory is not reclaimed it's probably getting GC'd later.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

ok thanks well ive been working on my code but it is absolutley terrible and its my first go at writing in c++. Its an assignment so ill give you the question and ill show you my code at the moment.

It's not bad. I'm sure you've used other languages so some of the syntax is colliding in your head.

This is what ive done it is deffinatley wrong bcoz im not sure how to do it properly but could you please help me out? or maybe check mine and give me some pointers?

I'll go through some of the errors in the code

#include <iostream>
using namespace std;


int main ()
{
	const int SIZE = 6;    //Array size
	
        //Rather than accounting for the menu choices why not make 
        //all of the arrays 5 and not have to deal with the empty slot in each
    
char DrinkChoice[SIZE] = { "Coca Cola", "Sprite", "Fanta", "Ginger Beer", "Powerade", "Shutdown"};  //Drink Names
	
         //You need to make this a string array.  You could make it a  
         //2D char array but strings are easier -- as it is you will only  
         //get 1 character out of each if it works at all

      int NumberDrinks[SIZE] = { "30", "30", "30", "30", "20" };  //Number of drinks..other array value are 0. 
	
           //strings belong in quotation marks, ints and doubles don't

double DrinksCost[SIZE] = { "1.50", "1.60", "1.70", "1.90", "3.50" };  //Cost of drink..other array value is 0.
	TotalMoney = 0.0;		//money count
	int password …
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

multiple loop exit in one single statement?

Do you mean if two while loops are nested? If so, you need a break at each level.

while(condition1)
{
      while(condition2)
      {
               if(condition3)
                    break;
      }
      
      if (condition4)   //you could definitely** make condition4 depend
             break;        //on condition3 via a flag or something
}

**whether or not this is the best practice, I honestly do not know