Duoas 1,025 Postaholic Featured Poster

OK, that helps.

This is a purely mathematical question. You'll need a function to tell you if a given year is a leap year or not. It so happens that the Delphi VCL has a function that does just that: uses SysUtils; function IsLeapYear( year: word ): boolean; Now think about how you can use that function to check each year for a leap year, and count how many leap years you find.

Hint: get out the construction paper and crayons and do it there first. This helps me all the time because by first solving the problem without the computer I have a better idea of how to tell the computer how to solve the problem.

Once you get some code together, post back here.

Duoas 1,025 Postaholic Featured Poster

Hey there. Here is your code more carefully formatted and with some commentary.

program Project1;
{$APPTYPE CONSOLE}
uses
  SysUtils;

type
  Tperson = record
            Name:        String;
            Dateofbirth: TDateTime;
            end;

var
  s:           string;
  FileA:       textfile;
  datestring:  string;
  personarray: array [1..5] of Tperson;  // very good
  personinfo:  Tperson;
  I:           Integer;


begin
  // You only need to set this global value once
  ShortDateFormat := 'd/mm/yyyy';

  // Good
  Assign(FileA,'PeopleInformation.txt');

  // The following reads each line of the file but
  // does nothing with it...
  Reset(FileA);
  while not EOF(FileA) do
    begin
    Readln(FileA,s);
    // See note 1
    end;
  close(FileA);

  // The following is a loop that properly reads each
  // record from file. However, like the first loop's 
  // s:string variable, the information is never used;
  // it is forgotten the next time through the loop.
  // See note 2
  Reset (FileA);
  while not EOF(FileA) do
    begin
    Readln (FileA,personinfo.name);
    Readln (FileA,datestring);
    personinfo.Dateofbirth:=strToDate(datestring);
    Readln ( FileA );
    end;

  // Here you try to print a variable you never initialized.
  // See note 3
  writeln (personarray[1].name, personarray[1].Dateofbirth);

  // Wait for the user to press ENTER before terminating
  readln;

end.

Note 1
Perhaps you made this loop because you wanted to see the file before putting it in a TPerson record? If so, replace the // See note 1 coment with: writeln( s ); Otherwise, you keep giving s a new value each time through the loop but you never actually use it. Neither s nor the loop have any purpose --you could just delete it and the code …

Duoas 1,025 Postaholic Featured Poster

Please read the announcements.

If you can come up with a good idea of what you want to do and how to do it we can help you along.

Post back with some (substantial) code.

Duoas 1,025 Postaholic Featured Poster

On linux? Or windows?

Duoas 1,025 Postaholic Featured Poster

Please use [[I][/I]code[I][/I]] blocks...

The default date format is 'm/d/yyyy', which is typical in the USA. I didn't look that closely at your dates... Before you call StrToDate say: ShortDateFormat := 'd/mm/yyyy'; Now the date/time functions will work.

The last date in your input is 30/02/1990 --which is invalid. February has no more than 29 days... and 1990 is not a leap year so the latest day in February is 28/02/1990.

Sorry about that.

Duoas 1,025 Postaholic Featured Poster

It sounds to me like your child process is misbehaving. May I ask which command you are executing?

Duoas 1,025 Postaholic Featured Poster

I think I see what you are doing.
Your angle is too small (and in the wrong units).

Consider, if you want a 5-pointed star: 360 /5 = 72, so each point is 72 degrees apart.
BUT you want to draw a line to every other point, so you will have to make the angle 72 * 2 = 144 degrees.

Since you are using radians, thats 2 * pi / 5 * 2 = 2.5133 radians.

Also, you will go around the circle twice, so you should make your loop a for loop counting how many points have been drawn.

When thinking about these sort of things, it really does help to get out a piece of paper and pencil and draw what is happening.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Er, it just occurred to me that file is a reserved word, not a directive, so it is illegal to use as a variable name. Also, I made a syntax error (using = instead of :=). So the code should be:

function readPersonRecordFromFile( var f: TextFile ): tPerson;
  var dateStr: string;
  begin
  readln( f, result.name );
  readln( f, dateStr );
  result.dateOfBirth := strToDate( dateStr );
  readln( f )
  end;

I'd have edited my last post but it seems that after a certain amount of time passes you can't...

Sorry. Hope this helps.

Duoas 1,025 Postaholic Featured Poster

/Me feels stupid

Perhaps I should get some sleep.

@tracethepath
To read a string as a character array then use cin.getline( a, 150 ); G'night all...

Duoas 1,025 Postaholic Featured Poster

That would probably be total overkill, but it would work...
Also, WaltP makes a very good point. Since this is a C++ program, would your professor totally object to using std::strings along with the rest of the STL?

Duoas 1,025 Postaholic Featured Poster

WaltP, I've compiled and tested the code. If count is zero then the spaces are written to the output file, and count is always reset to zero. It has no other effect on the code.

Duoas 1,025 Postaholic Featured Poster

I see... You're going to have to ask your professor for clarification on how he wants you to allocate to the array. There is no reasonably simple way to resize a dynamically allocated array in C++. A linked list would work...

Alas.


He might be looking for something along the lines of char *keys[ 50 ]; Where each key is a dynamically allocated array of char. But there is no way to dynamically allocate only part of the keys array at a time --it's all or nothing.

Duoas 1,025 Postaholic Featured Poster

Your compiler might be choking because you are mixing C and C++ I/O. While this isn't supposed to be bad, it sometimes is --particularly with older compilers.

Change your first few lines to:

string a;
char ch;
cout << "Enter a line of text:" << endl;
getline( cin, a );
ofstream file( "EXAMPLE.txt" );
file << a;
file.close();

In general, when coding C++ use the C++ way of doing file I/O, and don't use the C way of doing file I/O.

Also, every line that has the word count on it needs to be deleted. It is preventing those spaces from disappearing.

Hope that makes better sense.

[EDIT]
WaltP you missed the fil ifstream at the bottom... so he actually should see more output on the screen...

Duoas 1,025 Postaholic Featured Poster

If I understand what you want to do correctly, you want to do something like an associative array or a map where the first array simply indicates what type of thing is in the second array?
So: if (keys[ n ] == "name") cout << "Name = " << values[ n ] << endl; You need to read up on dynamic memory allocation and fix your syntax. Lines 14 and 15 each ask to allocate zero bytes of memory (an array of zero elements is zero elements long...).
Also, your syntax is screwy. Neither line makes any sense.

What errors are you getting from the compiler (the first few ought to be enough).


Frankly, since this is C++, you should be using a map<string, string> instead of an array of array of char.

Does this make sense?

Duoas 1,025 Postaholic Featured Poster

Never mix C and C++ I/O unless you know what you are getting in to. (Yes, the C++ standard says you can mix on the same target stream, but that is still somewhat vague and you mileage may vary with different compilers. Just don't mix unless you are forced to.)

That is the only thing I can see that can be messing you up...

Now, just get rid of every line with count on it and it should work just fine...

Duoas 1,025 Postaholic Featured Poster

You overload the istream whenever you want to do serial input. This requires your class to have a definite (and hopefully unique) way to store its data. You can format it any way you desire, so long as you can tell where it begins and ends.

So, for example, if you have a class named Employee:

class Person {
  string surname;
  string given_name;
  string job_title;
  time_t hire_date;
  float pay_rate;
  //etc
  };

You can pick all kinds of ways to save this information. One would be just to list each piece as a string in a text file:

Shunpike
Stan
Knight Bus Conductor
1993/4/12
$7.15

Bones
Amelia Susan
Head of the Department of Magical Law Enforcement
1972/5/19
$50.32

Given a file like this and an appropriately coded >> operator you could read in the data, knowing that there are five lines of data plus one blank line per record. No need to ask questions or do anything else.

It depends entirely on your storage requirements. In this example I chose a simple line-by-line data dump. It can be more carefully organized textual information (for instance, if your Employee data is mixed with other types of data), or purely binary. It is up to you.

However, you really should read up on serialization.

Hope this helps.

christina>you commented: great explanations. +15
Duoas 1,025 Postaholic Featured Poster

Watch your fencepost conditions. j can become negative.

Try tracing your sort using this input:

arr3 = 1 3 7 2 9 0 5
       j
         i
temp = 3

Good luck.

tracethepath commented: thanx...it worked +1
Duoas 1,025 Postaholic Featured Poster

Very good. Just a few thoughts:

In your functions, you keep doing stuff you already have functions for. In the new operator+ method, you create the Distance object first, but you still don't use it until you are ready to return a value. Hint, use: Distance d3( sizeInInches() ); Now use an overloaded operator method you have elsewhere to add d2 to d3. No need to play with the feet and inches, or normalize them, because the other functions you already have will do all that for you. Make sense?

Likewise, in your comparison methods (operator== and operator<) there is no need to find the total number of inches yourself. You already have the sizeInInches() function to do that for you. Also, there is no need to say if (x < y) return true; else return false; The < operator returns a boolean value, so just use it directly: return (x < y); Good luck.

Duoas 1,025 Postaholic Featured Poster

You can't.

What you can do, though, is have another string with all your other data, which you use to copy the valid characters to from the original string. Once you find a punctuation character, print the second string using the function given to you, then use the second string again in the same way until the original string is used up.

So your original idea will work except that instead of printing each character as you find it you just copy it to the end of a second string, which you print when you find a punctuation character.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

First, a short rant. Professors love to use stuff like this because it doesn't exist in real life and nobody will know how to help you (or help you cheat... but I won't do that). I had to go download all the stuff off of your textbook's website to learn about PC-3 (which, IMAO, is one of the most underpowered assembly languages I've ever seen). If they want to teach MIPS assembly, why not just use actual MIPS assembly?!!!
/end rant

The trick with assembly language is to think in fairly large terms, then for each term write a small series of instructions. You have already got a fairly good start. I'm not sure what you are doing after you RTN, but here are some thoughts on the min and max functions you are having trouble with. I will focus on R0 (min).

You've already got the current min in R0.
Each time through the loop you need to increment R2 by one, and load R5 with the value at R2. ADD R2, R2, 1 LDR R5, R2, 0 Now, copy R5 to R6 and negate R6 like you did for the comparitor.
Add it to R0, and check the result to see whether you are greater-than-or-equal-to R0. If so, you can safely jump to the next part where you will test the max (R1). Otherwise, make R0 equal to R5.
When testing for max, do the same sort of thing: if you test …

Duoas 1,025 Postaholic Featured Poster

Actually, you have done a very good job.

When you say: d1 = d2 + d3; you are actually doing two operations: d2 + d3 and then d1 = dtemp When you overload operators in-class as you are (that is, where the operator functions themselves are actually class methods instead of friend functions) what happens is that the left-hand operand's operator function is called with the right hand operand as the argument value. Hence: d2 + d3 is really the same thing as: d2.operator+( d3 ) When adding two things, you want to return a new value without modifying either of the addends, which is why I had you change it.


Now, what I'd like you to notice is that you had to repeat yourself to avoid modifying d2: you created two ints and did the same thing that normalize() does, and only then created a new Distance object as the return value.

Why not first create the new Distance object (instead of two ints), set it equal to d2, then add d3 to it with a function you already have, then return the new distance object?

Does that make sense?

Duoas 1,025 Postaholic Featured Poster

That is a very good start. Now all you need to do is read data from the file and stick it in the record.

For the following examples, I have the hypothetical variable: var person: tPerson; The first thing to read is a string, all by itself on a line, so readln( fileA, person.name ); works just fine.

In the Delphi IDE, place the cursor over the word TDateTime and press F1. You'll get the help for that type. Up at the top there is a link that says See also. This will give you a list of things related to the tDateTime, including functions to read and write it from string. I found StrToDate in the list. So, you can read the next line as:

var dateString: string;
...
readln( fileA, dateString );
person.dateOfBirth = strToDate( dateString );

Don't forget that there is still that blank line to read: readln( fileA ); Put these three together and you have read a single record from file and stored it in a Pascal-style record.

You could make a function that does this for you:

function readPersonRecordFromFile( var file: TextFile ): tPerson;
  var dateStr: string;
  begin
  readln( file, result.name );
  readln( file, dateStr );
  result.dateOfBirth = strToDate( dateStr );
  readln( file )
  end;

Keep working at it. Hope this helps.

PS. I'm not too fond of just giving code away when you are learning something new. Please pay attention to the thought process that went into creating this …

Duoas 1,025 Postaholic Featured Poster

All the answers given you have been very clear. Some even posted code that works just fine.

What's not too clear is your teacher's brain if she gave you a homework assignment to clear the screen using C++...

Duoas 1,025 Postaholic Featured Poster

I recommend the GCC. It comes with C and C++ and is fully standards compliant.

If you want an IDE I'm not sure. Maybe someone else has a suggestion for that...

Duoas 1,025 Postaholic Featured Poster

OK. Your class stores two pieces of information: feet and inches.
Every foot is 12 inches, so if a distance is 70 inches you can't just store it as feet without rounding it up or down to the nearest foot. If you look at normalize() you'll see that you take those 70 inches, get the 70/12=5 feet out of it and store that in feet, and store the remaining 10 inches in inches.

Likewise, the sizeInInches() works in reverse. The return value is the total number of inches, which is ((feet * 12) + inches), right? By using a local variable you are correct. Create a new int inside your function, do the proper calculations to give it a value, and return it.

int result;  // create a local variable (one we'll forget when the function is done)
result = feet * 12;  // convert feet to inches
result += inches;  // add any remaining inches
return result;  // return the total inches

Notice how I used the mathematical formula exactly?

Making things work is just a matter of not giving up. Eventually you'll make sense of it.

Good luck.

Duoas 1,025 Postaholic Featured Poster

[EDIT] Balla4eva33 posted the last message as I was posting this one, so this should be read as post #4 and balla's post #4 as post #5.[/EDIT]

Don't feel stupid. You are just going through what we all do (or did) when learning this stuff. Just keep thinking about it, and reading about it, and trying stuff. Eventually you'll "get" it.

I've already given you a pretty "dumbed down" answer (yeah... don't feel bad). Try to think it through for a day or so and if you are still completely lost post again and I'll help more. Even if your new tries don't work, post them.

Makes your brain feels like a walnut in a nutcracker, no?

Oh yeah, here's a good hint: don't write the same code over and over again. Notice how the sizeInInches() method (i.e. class function) is private. That means it is only meant to be used by methods of your class, such as the int() operator function and your comparison operators and etc. It is perfectly OK to use it over and over again.

Think about it and post again.:cool:

Duoas 1,025 Postaholic Featured Poster

What you are doing is essentially this:

int main() {
  char *s;

  s = (char *)malloc( 1000 );
  s = NULL;

  // what happened to the 1000 characters?
  }

You allocated space on the heap, then you promptly threw away the address of the space you allocated. There is no way to get it again. The space is lost to you --at best until you end your program and at worst until you reboot.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Everything after db is a byte. This sequence of bytes is obviously meant to be used as a character string, so everything in it is a character.

13, 10 is the ASCII character codes for CR and LF, meaning Carriage Return and Line Feed. In other words, it will print "....Hello world...." and then move the cursor to the beginning of the next line.

In C it is the same as "....Hello world....\n".

Hope this helps.

[EDIT]
Oh yeah, the zero means 'end of string'. Strings are often stored as ASCIIZ, meaning they are ASCII character codes and terminated with a zero.

Duoas 1,025 Postaholic Featured Poster

There is no way to do this without system dependencies. C++ doesn't know anything about the output device, so if you want to play with it you have to know something about it.

It is possible to write your C code to choose to compile specific options depending on what OS you are using, but that is a rather clunky option.

Another option is to write several separate cpp files that each define the same function, but implement it differently depending on the OS. Compile and link the one appropriate to the OS. (This is the most common option.)

For just playing with the console though, I recommend you to look at the curses library. There are several versions: curses, ncurses, and pdcurses. I recommend the latter. It is available on most POSIX capable systems, including windows.

If you want something really simple, and you have ANSI.SYS running on your Windows PC, you can just code: cout << "\33[2J"; If it works it works. If not you'll just get some junk on the screen.

Sorry I couldn't be of more help.

Duoas 1,025 Postaholic Featured Poster

I didn't know you could make applets using Pascal... Are you sure you aren't using Java or somesuch?

Either way, remember that your substitution cipher is composed of two separate pieces of information: the code word and the remaining alphabet: code word + remaining alphabet You can consider each part separately.

To create the remaining alphabet, just say the alphabet but leave out the letters found in the code word.

A thought: what happens if your code word has duplicates?

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Whenever you read the word "structure" always think record (or class, but you haven't gotten that far yet...).

So create a record with a string for the person's name and some numbers for his birth date.

Then, when reading the file, be careful to pay attention to the shape of the input. In this case, each input record has three lines:
name
birth date
blank line
So for each record you read you will have to read three lines.

You can use dynamic arrays, but if you haven't been taught that yet, just make an array of 100 or so records, and count how many records you put in the array as you read the file.

while not eof do
  begin
  read record
  number_of_records := number_of_records + 1;
  store the record you just read at the next empty location in the array
  end

Then just loop through the array and find index of the oldest person. Once done, print that record.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Ah, your edit.

fork() returns one of three things:
- a negative number on error (which you know)
- zero if you are the newly created child process
- the PID of the child process created if you are the parent process

A signal handler isn't supposed to return anything. Here is a good reference I just googled.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Yes, I understand that. What are you trying to do with that signal function? Are you trying to make something of a signal handler that calls another signal handler and crashes the program if the other handler fails? (If so, that's smart idea, but still not a very good thing to do.)

Duoas 1,025 Postaholic Featured Poster

You have two problems that I see.

The first is that you are using the struct tag without the struct keyword: korifi *a[100]; I think you meant to say this: kdiktis a[100]; The next problem is that you are throwing memory away:

root->a[s] = (kdiktis)malloc(sizeof(struct korifi));  // allocate big chunk of memory
root->a[s] = NULL;                                    // throw it away (memory leak)

Also, I don't understand Greek and online translators are particularly bad at handling words used in source code, so I have no clue whatsoever what you are trying to do. Please translate stuff into English before posting on an English forum...

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

No, the call to fork() is correct --I see nothing wrong with it.
You are aware that this is a *nix system function and it will not work on Windows, right?

I'm not sure what you are trying to do with the signal. Are you trying to make a pointer to a function or a function itself? Choose one. (And either way, watch your syntax!)

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I think this will do what you want:

proc main {ip port} {
  set connection_to_server [socket $ip $port]
  puts $connection_to_server "Hello TCP-IP World\n"
  close $connection_to_server
  }

main  127.0.0.1  6789

If you need your tcl script to be directly executable from the command line I'll need to know more about your OS.

Oh yeah, you can always get this kind of info from one of
Tcl/Tk 8.5 manual pages
The Tcler's Wiki

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Your question is much too vague for me to help you.

What is it you wish to classify?

Duoas 1,025 Postaholic Featured Poster

Nobody learns if you just give them answers. My post was as close to it as I dare go.

The trick to programming hasn't anything to do with syntax or language or loops or anything. It is thinking about the problem.

Duoas 1,025 Postaholic Featured Poster

The int() operator should return sizeInInches(). Also, watch it, your sizeInInches() function is not correct: you return the number of feet in inches but forget any extra inches there may have been in inches before calling the function. Since you don't want to normalize or un-normalize, use a local variable instead of modifying inches.

Your += operator is perfect. However, your + operator is not. Assume: d1 = [b]d2[/b] + d3 (not what you've got written above the function definition). Never modify the objects on either side of the + operator. The user wants a new object (d1). Hint: make a new return value as a copy of d2, then add d3 to it, and then return it.

When doing '+= int' think again what the int stands for: number of inches. Just add the int value to the inches and normalize.

In your comparison operators (== and <), be careful. You want to compare the sizeInInches(). (Also, be careful what it is you divide by 12 --moot point.) Finally, return (x < z) ? true : false; is a bit wordy. The expression x < z itself returns a boolean value, so you really only need to say: return (x < z); That should be enough to get you right. Good luck.

Duoas 1,025 Postaholic Featured Poster

Yes, yes, exactly. Thank you.

I've nothing against memcpy(). Just using it improperly.

iamthwee commented: I can't believe you don't use video tutorials they save hours! Thanx +13
Duoas 1,025 Postaholic Featured Poster

Actually, your array is row arrays of SIZE chars. Just use a std::string instead of an array of char. string word[ row ]; For those that missed the answer to the last thing, mychar can be any lowercase character, but you always subtract ('a'-'A') from it.

Glad to be of help.

Duoas 1,025 Postaholic Featured Poster

Make sure use use the code I gave you here and it will:

hide the application button from the taskbar (ApplicationActivate proc),

prevent it from reappearing (SysCommandMessage message proc), and

display a button for your main form (CreateParams proc) [but only when the main form is visible].

Good luck.

Duoas 1,025 Postaholic Featured Poster

I'm sure you are getting a perfectly fine return value. Your problem is that you have not supplied any type information that the compiler can use to "know" about your array.

First, please see the Wikipedia here.

Next, please be aware that only the first dimension can be [] in C, and only when you are not actually creating data. Other dimensions must have a size. So int Mat[][][]; is an error, as is int Mat [][10][5]; but void printarray( int a[][10][5], int depth ); is not.

However, int *Mat; knows nothing about how many dimensions the array has, or even if it really is an array.

If your array has variable size dimensions, then you should use a simple flat array (or pointer) and calculate things on your own:

int *index_2d_array( int *arr, int height, int width, int y, int x ) {
  int index = (y * width) + x;
  return &(arr[ index ]);
  }

// two differently sized arrays with a "center" element
int a[5][5] = {
  { 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0 },
  { 0, 0, 7, 0, 0 },
  { 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0 }
  };
int b[3][5] = {
  { 0, 0, 0, 0, 0 },
  { 0, 0, 4, 0, 0 },
  { 0, 0, 0, 0, 0 }
  }
// a[3][4] = b[1][3]
*index_2d_array( a,   5, 5,   3, 4 ) …
Duoas 1,025 Postaholic Featured Poster

Neither language can do this. "Bold" is a feature of your output device.

What kind of output device are you using? Is it a console window? (If so, what OS?) Is it a Windows Rich Edit control? Is it something else?

Let us know and we can give you some C++ code to do it, or point you to a tutorial or documentation on how to do it...

Duoas 1,025 Postaholic Featured Poster

C++ doesn't really know the difference between an int and a char: both are just numbers but one is typically 8 bits wide and one is typically 32 bits wide.

I/O routines know that the string of numbers you give it are meant to be printed as ASCII if it is type char, or converted to an ASCII representation of the number if it is type int. That is the only difference.

So, you don't need the static_cast stuff.

Also, a lowercase letter can be made uppercase just by subtracting the difference between an ASCII lowercase and uppercase letter: mychar -= 'a' - 'A'; Assuming ASCII is inherently non-portable (though most PCs do actually use either ISO-8859-1 or ASCII), so you can #include <ctype> to get routines that will do this for you: toupper() and tolower().

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

BTW, were you able to get that last bit of code I gave you to work (to display the main form's button instead of the application's button on the taskbar)?

Duoas 1,025 Postaholic Featured Poster

OK, I found the component on the web.

All you need is the TIcon you wish to display. You can load it by sticking a TImage component on your form, setting its visible property to false, and accessing the TImage's picture.icon property.

Then just set the icon property of the tTrayNotifyIcon component:

TrayNotifyIcon1.icon := Image1.picture.icon;

The icon on the taskbar should update automatically. Keep in mind that if you may have to save the old icon if you want to restore it later.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You are very close. You just need to add a couple of things to your loop.

#include <iostream>
using namespace std;
int main()
{
  // The sum of no numbers is zero, so...
  float sum_of_positive = 0.0;
  float sum_of_negative = 0.0;

  for (float counter=-2.3; counter <= 3.0; counter+=.4)
  {
    cout << counter << " ";
    // [B]todo: if counter is less than zero, add it to the sum_of_negative[/B]
    // [B]todo: same kind of thing for positive numbers[/B]
  }

  // [B]todo: print out your sums here[/B]

  return EXIT_SUCCESS;
  }

Hope this helps.

[EDIT]
man, too slow again...

fooey.

Duoas 1,025 Postaholic Featured Poster

I think you need to go sit down with your professor and work on this a little with him. There are a lot of syntactic and logical errors in here, which I think you can best overcome by working with someone face to face. He shouldn't give you a hard time. Most professors are genuinely pleased when students ask for help understanding a problem. (If for no other reason, it gives them a chance to talk about it more.)

Before you go, google "merge sort" to find some good animations of what is going on. Ignore the stuff in the WikiPedia. (There's nothing wrong with it, it'll just confuse you and your professor will know if you scavenge code from it --honestly, it would be really obvious.)

I was going to give you a bunch of stuff about a binary tree (which is a form of linked list) but I think you ought to go see your professor first. Most merge sorts are done using recursion instead of using an actual binary tree in memory --which is how you are trying to do it.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Erm, the program is doing exactly what it is told to do. The error is that it is doing something you would prefer it not to do? Or that it is not doing something you would like it to do?

Whenever you are getting a string from the user at the keyboard, don't use cin >> mystring; Use instead getline( cin, mystring ); As I am not sure what exactly this is supposed to be doing I can't be definite, but this should solve some problems you are having and allow you to get rid of that cin.ignore(); statement.

(BTW. If you say: cin >> text; cin.ignore(); and the user types "This is a test" then only "This" is stored in text and " is a test" is ignore()d.)

Also, the #pragma once is a compiler-specific and problematic solution. You really should use well-named include guards instead.

Hope this helps.