Duoas 1,025 Postaholic Featured Poster

[EDIT]
I didn't read to carefully. The compiler is so old it doesn't create Win32 exes. You'll have to use a utilit like HiddenStart: http://www.ntwind.com/software/utilities/hstart.html.

The following changes the subsystem type for Win32 exes.
[/EDIT]

#include <stdio.h>
#include <stdlib.h>

#define then

int main( int argc, char **argv ) {

  FILE *f;
  unsigned long  v = 0;
  unsigned short i = 0;
  char sig[ 4 ];

  if (argc != 2) {
    printf( "%s",
      "usage:\n"
      "  chss EXEFILE\n\n"

      "  Changes the subsystem type of the named exe file and reports the new\n"
      "  status: console or gui.\n\n"

      "  The file MUST be a PE32 or PE32+. No checking is done to verify that!\n"
      );
    return 0;
    }

  if ((f = fopen( argv[ 1 ], "rb+" )) == NULL) {
    fprintf( stderr, "Couldn't open %s", argv[ 1 ] );
    return 1;
    }

  /* addr of PE header signature */
  fseek( f, 60, SEEK_SET );
  fread( &v, 4, 1, f );

  fseek( f, v, SEEK_SET );
  fread( sig, 4, 1, f );
  if ((sig[ 0 ] != 'P') || (sig[ 1 ] != 'E') || (sig[ 2 ] != 0) || (sig[ 3 ] != 0)) {
    fprintf( stderr, "%s is not a PE32 or PE32+", argv[ 1 ] );
    return 1;
    }

  /* addr of subsystem code */
  v += 4 + 20 + 68;

  /* get current code */
  fseek( f, v, SEEK_SET );
  fread( &i, 2, 1, f );

  if (i == 3) 
    then { …
Duoas 1,025 Postaholic Featured Poster

Actually it is quite vague.

To my mind, the most probable meaning is that you are to write a function that takes a vector as argument, finds both the largest and smallest values in the vector, and returns (largest minus smallest).

Read another way, you might have to write a function that takes two values and returns a vector iterating from the smallest to the largest.

Either way, the type T must have collative properties (having at least operator< defined) and additive properties (having operator+ and/or operator- defined). A good type T would be int, for example.

I would go and ask your professor for clarification.

Duoas 1,025 Postaholic Featured Poster

No, i use XP and here is the code I was trying to use http://www.planet-source-code.com/vb/scripts/ShowCodeAsText.asp?txtCodeId=10405&lngWId=3
Also I am the admin on my pc so I should be able to do whatever I like with the files shouldnt I?

Believe what you like. Your error message is ld returned 1 exit status which explicitly means your linker is failing for some (unspecified) reason.

Check to make sure the compiler is correctly configured to use the linker.

Also, admin doesn't mean you have unfettered access. Just privileges sufficient to override access restrictions. That said, my first, off-the-cuff diagnosis was probably premature.

Duoas 1,025 Postaholic Featured Poster

Use the ord function. print ord('A') Prints the number 65 to the console.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I know this sounds funny, but you need to get out a piece of construction paper and some crayons and draw yourself a house.

Then, using your finger, 'click' on the picture where the instructions say and in the order they say. For example,
1: click on lower-left corner of house
2: click on upper-right corner of house
3: click on the center of the top edge of the front door
4: click on the center of the window
5: click on the top point of the roof

As you do that, think about what information you must calculate at each step. You will have to reuse information you gained at previous steps.

I also recommend that you draw something the instant you can to provide user feedback.
So after the first two clicks, draw the rectangle.
After the next click, draw the door.
After the next click, draw the window.
And after the final click, draw the roof.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I'm not sure what exactly it is that you want.

XRC is a file format used by wxWidgets programs to store the layout and arrangement of buttons and other widgets on a form. A program that uses wxWidgets can create a form using this resource format.

The file is an XML file. There shouldn't be any code in it at all.

Could you be more specific as to what you are trying to do?

Duoas 1,025 Postaholic Featured Poster

It isn't the code that's complaining, it is the linker (ld).
Most likely you are trying to write to a file that is read-only, or read or write a file that you don't have access rights to. Are you using linux?

Duoas 1,025 Postaholic Featured Poster

Er, I haven't looked entirely through everything, but you seem to have the right idea mostly.

Your copy constructor point::point( point &pnt ) should not be setting x and y to zero, but rather to the same values as the pnt variable's x and y.

You also have too many copy constructors: point::point( point &pnt ) point::point( point &spoint ) point::point( point &spoint ) It doesn't matter what you name the argument variable; all that matters is the type of the function. All of them have the same type: point::point( point & ) Pick one and stick with it. I think you are getting confused because you also have variables named spoint and epoint. Remember, a class is a data type, but spoint is an actual piece of data. You can compare it to the architectural blueprints to a house (the class or type) and an actual instance of the house (a variable). You can have as many houses of a specific type as you like, but the blueprints don't change.

The overloaded operator= is similar to a copy constructor, so the two functions should look very much the same. Watch your types. In the class definition you have prototyped point operator=( point ) but the type of the function below is void point::operator=( point & ) I know it is difficult to find clear information on how to overload various operators. Make sure you use your textbook. The type of the overloaded operator should be: point …

Duoas 1,025 Postaholic Featured Poster

The file QBASIC.HLP is not a Windows Help file, so WinHelp cannot open it.
You need a program named HELP.COM. If you google olddos.exe you should find the Microsoft package that contains QBasic and other utilities, like Help.com.

Hope this helps (pun intended) :icon_lol:

Duoas 1,025 Postaholic Featured Poster

It is good that you are thinking in terms of separating out functions in your code.

In this case, there is no compelling reason to do it either way. Each loop must iterate through the exact same sequence of numbers.

If you were to use two separate loops though, you would need to store the numbers obtained by the first loop somewhere (such as in a vector or list or an array), then loop through them again to calculate their average.

Write your (one) loop as if you were calculating the average. Only instead of getting the next number from an array or something just get it from the user. When the user gives you the sentinel quit the loop, finish calculating the average, and print it.

Hope this helps.

iamthwee commented: glad to see you posting again. +12
Duoas 1,025 Postaholic Featured Poster

Indeed it is.

Consider the following lecture a bonus :icon_cheesygrin:

If you plan to use printf you should #include <cstdio> at the top of your program.

Recursive functions are best avoided in languages like C++ because they don't have any form of tail recursion. Basically, every time you call the function (again) it uses more stack space. If you recurse too much you can crash your program. (The few cycles in your example here are fine though.)

Almost everything done recursively can be done just as easily imperatively (using loops), the bonus being that you don't use up more space at each cycle.

Keep in mind, recursion isn't evil, and is sometimes necessary. If you are just playing around with it, you might want to try something using mutual recursion next.

Nice job!

Duoas 1,025 Postaholic Featured Poster

Windows executables have a flag in the header that causes that console window to appear or not.

Try changing

int main( int argc, char **argv )

to

#include <windows.h>
#include <shellapi.h>

int WndMain() {
  int argc;
  wchar_t **argv = CommandLineToArgvW( GetCommandLine(), &argc );

Notice that by compiling a Windows application your command line is now an array of wchar strings.

If that doesn't work, post back and I'll give you a little program to change the exe subsystem type manually.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Google "mmap".

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Don't give up yet. I failed to account for the MDI child forms.

The icon/button you see on the taskbar actually belongs to the application, and not the main form. So if you have any windows other than the main form open (you can't hide a MDI child form) the application button will automagically appear on the taskbar.

The trick is to get rid of the application button and put the main form's button on the taskbar instead.

Like I said, I haven't played much with MDI applications before so I've had to learn some stuff to help. I'm cleaning up my code now. Give me another day or two and I'll post an example that does everything you want (and then some) with full source code you can scavenge as you like.

Duoas 1,025 Postaholic Featured Poster

@mufti
You are writing out ArraySize items each frame. According to your read function it looks like you want only one dist and one ampl per frame.

Duoas 1,025 Postaholic Featured Poster

Well, you people win. Whether or not you like it I generally have a pretty good idea what I am talking about and don't like being chopped at for helping someone out. I can live with honest mistakes (such as with sizeof --I just always used parens). But being contradicted to satisfy your own arrogant egos is too much. If you all had spent any time reading the contents of this thread you'd find a lot less to fault me with.

I hate snot.

Btw. Any C compiler that considers a or &a[0] the same as &a is just waiting to punish people. Understanding how pointers work is very much the business of the programmer --as without that knowledge they'll wind up regurgitating circular crap on some random forum. Go grabbing the address of some pointer variable on the stack and treating it the same as the address the pointer variable contains at your own peril. You might want to study how linkers arrange data into a PE32, and how the windows loader puts it into memory, as well.

@fmufti
How you arrange your data is up to you. If you want to write the frame number as an integer before writing all those doubles then that would work. Just read the data back in in the same order you wrote it out.

Also, put while (!kbhit()) to continue while a key has not been pressed.

Bye.

Duoas 1,025 Postaholic Featured Poster

Hey again zandiago. Watch your syntax.

switch (sentence[ i ]) {
  case 'A': case 'a':
    total += A;
    ++numChars;
    break;
  case 'C': case 'c':
    total += C;
    ++numChars;
    break;
  ...
  }

You are correct in that if a char is not in the switch then nothing is added to your total (nor numChars).

I would also add a case for whitespace and other end of word markers to reset total and work on the average stuff per word.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

The answer actually depends on which version of Windows you are using. Also, since this is a batch file, you want to suppress questions like "Do you really want to delete X?", which will really confuse and frighten your end-user.

Here's a batch that should work on all versions of windows for you: redir.bat

@echo off

if %1.==. goto usage

if exist %1\nul goto deldir
goto newdir

::------------------------------------------------
:deldir

:: Determine if we are using Windows 2000 or XP
ver | find "XP" > nul
if %ERRORLEVEL% == 0 goto xp-and-2000

ver | find "2000" > nul
if %ERRORLEVEL% == 0 goto xp-and-2000

goto nt-and-older

:xp-and-2000
rd /s/q %1
goto newdir

:nt-and-older
deltree /y %1

::------------------------------------------------
:newdir
md %1
goto end

::------------------------------------------------
:usage
echo usage:
echo   %0 DIRNAME
echo.
echo Deletes the directory named DIRNAME and everything in it if it exists!
echo Then creates a new directory named DIRNAME
echo.

:end

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Salem, so far I've only seen you give good advice. So don't be stupid now.

1. Arrays in C/C++ are managed by having a variable that points to the first element in the array. The only difference between a[0] and *a is compiler magic.

2. He was saying sizeof read_dist. In case you didn't notice, read_dist is a variable, not a type.

3. His original code didn't work, hence his taking the time to post here.

4. That is not the reason he is not getting ampl data. If it were just a matter of buffer overflow he'd still get his ampl data since the array is declared in memory immediately following the dist data. It would overflow straight into the correct place.

The reason was that he was giving the address of the pointer to the array data, rather than the address of the array data. Hence, he was reading into his code segment, which Win32 prohibits. Hence, there are two reasons his program should have crashed: Win32 would complain; barring that he would destroy his code before it got to the read_ampl part. Lucky he didn't have some bad opcodes in his dist data.

Good thing: yes, writing out the size of the array is a good idea.

Duoas 1,025 Postaholic Featured Poster

Wow, you're awake too...

The problem is when you changed read_dist and read_ampl from static arrays to pointers. The sizeof() operator always gives the size of the object indicated. The size of an array is much larger than the size of a pointer.

So, you'll have to change things thus:

filein.read((char *) read_dist, sizeof( double ) * ArraySize ); 
  filein.read((char *) read_ampl, sizeof( double ) * ArraySize );

Sorry for the confusion. I should have warned you about that...

Duoas 1,025 Postaholic Featured Poster

Heh, you've really gotten yourself into a pile of beans. The inverse is the adjugate over the determinant. There is no simple answer. Google those and good luck.

PS. Come back with some code and we'll try to help you more.

Duoas 1,025 Postaholic Featured Poster

Is this to be production code? I assume it is so my response might be a little more embarrassingly detailed than you would like...

First, for your main problem. I think you are clobbering memory somewhere --I'm actually surprised your program isn't crashing. Try this:

filein.read((char *) read_dist, sizeof( read_dist )); 
   filein.read((char *) read_ampl, sizeof( read_ampl ));

Remember, read_dist is a pointer to double. You are casting it to a pointer to char. Either way what it points to is the first double in the array, but you were giving the read function a pointer to the pointer to the first double in the array...

Second. the sizeof requires parentheses. It's nice you know a double is eight bytes long, but you should (if just for style) not count on it. Say: sizeof( double ) * ArraySize and sizeof( read_dist ) Third, (and I realize that this is just testing), try to get rid of all the hard-coded stuff and stick to using ArraySize. In your production code use double *read_dist = malloc( sizeof( double ) * ArraySize ); or double *read_dist = new double[ ArraySize ]; to allocate memory for the array. Use free or delete when you are done with it.

Fourth, it is good that you are testing for errors, but there are currently no consequences. For example, if opening the file fails you print out that it did then try to read a huge array anyway. While this code works fine, it …

Duoas 1,025 Postaholic Featured Poster

Heh, sorry to be confusing. (I'm starting to be a little disappointed with some of the C++ classes people are taking.)

The #include <iostream> statement means that the compiler sticks all the code and definitions and stuff in the "iostream" file into your program. That way you can use cin and cout.

I used <limits.h> just because it defines the largest and smallest possible numbers. If you want, get rid of the line that includes the file and replace INT_MAX with some really, really big number, and INT_MIN with some really, really negative number.

If you haven't learned about converting between int and std::string yet then use tracethepath's method of using some specific number as the SENTINEL. It doesn't have to be -99 or even the same number every time --you could ask the user for a number to use as the SENTINEL.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Wh.. what... your teacher gave you that code? He should be fired.

For your language questions, this is a really handy site. http://www.cppreference.com/
Click on the part for C++ I/O to find putback and the like. (BTW. Don't use putback in your code. If you ever actually do have to use it, you'll know enough about programming to know when you need to use it.)

A number's radix (or base) is a textual representation for use by humans. No matter what the number's base it is stored in the computer exactly the same way. Hence, when you read the number from its textual representation you've done 99% of the work. All you need to do is send the int to cout to see its decimal representation.

For converting the input into a valid number you are on the right track. Lets break down the number 789 (decimal). That's 700 + 80 + 9, or (7 * 10^2) + (8 * 10^1) +(9 * 10^0). [When I say 10^N I mean ten raised to the power of N.]

The same holds true for other bases. In base 5, 342 is (3 * 5^2) + (4 * 5^1) + (2 * 5^0). Notice also that the exponent is 0 for the ones position, 1 for the tens position, 2 for the hundreds, 3 for the thousandths, etc.

Finally, remember that if you want to shift a number up one decimal place, just multiply it …

Duoas 1,025 Postaholic Featured Poster

Actually, you've got things just about right. The problem is that you are calling main() from the other functions. Don't do that.

In between lines 16 and 17 add: while (TRUE) { end the while statement between lines 41 and 42: } Then, get rid of every instance of main(); . That is, get rid of lines:
39, 52, 53, 55, 71, and 85.

You might also want to reconsider why so many of your functions return a value. For example, checkPrime() always returns zero, and the return value is ignored anyway (line 28), so just make it void checkPrime( int ); and

void checkPrime( int number ) {
  int n=number, den;
  for(den=2; den*den<=number; ++den){
    if(number%den==0){
      printf("Your number is not prime.\n It is divisible by %d.\n", den);
      return;
    }
  printf("Your number is prime.\n");
  }

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Heh, y'all missed my favorite really stupid language: Whitespace.

Say hello.

Source: whitespace examples.

BTW. That "Say Hello." thing at the top is just a comment...

Duoas 1,025 Postaholic Featured Poster

Whomever wrote this code was a little confused himself. I suggest you come up with your own solution.

p, q, and r are pointers to characters, not character arrays.

The first while loop reverses the string in s[] and puts the result in t[] (but it forgets the null terminator).

The second loop starts out with r pointing to the last character in s[] and q pointing at the first character in s[]. The loop then increments q and decrements r so long as the characters they point to are equal. If the string in s[] is a character-by-character palindrome (including spaces, punctuation, etc.) then r will be equal to s-1 when the loop terminates. You'll notice that t[] is completely forgotten...

Again, forget this code and come up with your own solution. The idea of copying only characters that we want to consider (such as A-Z, 0-9, etc.) from the string the user input to another string is a good idea.

Another good idea is starting a character pointer (q) at the beginning of the string containing only valid characters and one (r) at the end and doing like in loop 2, but ending when r < q.

Finally, use better variable names than s, q, r, etc.

Good luck.

Duoas 1,025 Postaholic Featured Poster

Er, C languages don't permit subfunctions. Try this:

#include <iostream>

void run();
int process( int larger, int smaller );
bool isOdd( int number );

void main() {
  char c;
  do {
    run;
    for (c = 'x'; (c != 'Y') && (c != 'y') && (c != 'N') && (c != 'n');) {
      std::cout << "Would you like to run again (yes/no)?" << std::endl;
      std::cin >> c;
      }
    } while ((c != 'N') && (c != 'n'));
  }

void run() {
  int numA, numB, x, result;

  // Get the two integer numbers from the user
  std::cout << "Please enter two integers to multiply:" << std::endl;
  std::cin >> numA >> numB;

  // Force numA to be the larger number:
  if (numB > numA) {
    x = numA;
    numA = numB;
    numB = x;
    }

  result = process( numA, numb );

  std::cout >> "ZanDiego  Class 12  Oct 16, 2007 2:30pm\n";
  std::cout << numA << " times " << numB 
            << " by conventional math = " << (numA * numB) << std::endl;
  std::cout << numA << " times " << numB
            << " by Brown's method = " << result << std::endl;
  }

int process( int larger, int smaller ) {
  // your code here
  }

bool isOdd( int number ) {
  if ((number % 2) == 1) return true;
  return false;
  }

You'll notice I've only used code that you have supplied except for:
- I've improved a few of the prompts to better language
- The main() function

Duoas 1,025 Postaholic Featured Poster

Me again. I just made an MDI that lives in the System Tray without any trouble (~30 min). My only guess is that the trayicon component is doing something that is messing you up. So... here's what I can do for you.

How to put your application in the system tray using Delphi 5.

File: SystemTray.pas

unit SystemTray;
interface
uses Windows;

const
  WM_ICONTRAY = WM_USER +1;

  NIM_ADD     = 0;
  NIM_MODIFY  = 1;
  NIM_DELETE  = 2;

  NIF_MESSAGE = $00000001;
  NIF_ICON    = $00000002;
  NIF_TIP     = $00000004;
  NIF_STATE   = $00000008;
  NIF_INFO    = $00000010;
  NIF_GUID    = $00000020;

type
  tNotifyIconData = record
    size:            cardinal;
    wnd:             THANDLE;
    ID:              cardinal;
    flags:           cardinal;
    callbackMessage: cardinal;
    icon:            HICON;
    tip:             array[ 0..63 ] of char;
    end;

function Shell_NotifyIcon( message: cardinal; var pnid: tNotifyIconData ): BOOL;
  stdcall; external 'shell32.dll' name 'Shell_NotifyIcon';

implementation
end.

File: MAIN.pas

unit Main;
interface
uses
  ..., SystemTray;  // add the new unit to the end of your uses clause

type
  TMainForm = class(TForm)
    ...
  private
    // used when hiding the application from the taskbar
    f_ExStyle: cardinal;
    // used to add the application's icon to the system tray
    f_TrayIconData: tNotifyIconData;
    ...
  public
    procedure TrayMessage( var msg: tMessage ); message WM_ICONTRAY;
    ...
  end;

implementation

...

procedure TMainForm.FormCreate(Sender: TObject);
  begin
  // remember the proper display mode for the application
  f_ExStyle := getWindowLong( application.handle, GWL_EXSTYLE );

  // add the application icon to the system tray
  with f_TrayIconData do begin
    size            := sizeof( tNotifyIconData );
    wnd             := handle;
    ID              := 0;
    flags           := NIF_MESSAGE or NIF_ICON or NIF_TIP;
    callbackMessage := …
Duoas 1,025 Postaholic Featured Poster

Tracethepath's code is a little unorganized. He is using the number -99 as the SENTINEL code to tell the program you have finished entering numbers. So if the number is -99 he breaks out of the loop. The only problem with that is that you cannot enter the number -99 as part of your list.

In my code, I goofed. I am using the empty string as the SENTINEL, but the code that reads input should be

std::getline( std::cin, s );

That way, the user just enters numbers, and when he is done he just presses ENTER once more.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

What OS are you using?

If it is x86 google "dos interrupt 21h".
If you are on a MIPS processor you'll need to google "mips syscall".

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

True. It is all the edge cases that various different compilers are likely to get wrong.

Duoas 1,025 Postaholic Featured Poster

The open() function only takes char * as an argument --it won't take std::string. Say this instead:

infile.open( filename.c_str(), ios::in );

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Bump.

It seems that the problem is that GCC won't let me pass NULL as a template value. There are two types of property access: direct and indirect. Direct access is when the property links directly to a class variable. Indirect is when the property links to a class method. I wanted to have the ability to use direct as well as indirect access, so my template includes fields for both types:

template<
  ...
  ValueType (Container::*getf)(),              // indirect read access
  void (Container::*setf)( ValueType value ),  // indirect write access
  ValueType Container::*getv,                  // direct read access
  ValueType Container::*setv                   // direct write access
  >

I've tried all kinds of variations, even using different types of explicit casts (static_cast, dynamic_cast, etc.) but the GCC doesn't seem to take anything except the exact type. The whole point was to include only those types applicable to the access type of property, and let the property class decide how to get/set a value based upon whether an accessor is NULL or actually points to a field or method.

I've already done all this using separate template classes for each property access type, but that septuples the number of operator overloads I have to write...

If anyone knows how to subdue GCC please help!

Duoas 1,025 Postaholic Featured Poster

Ah, yes, you're right. I didn't crunch the examples like I should have. The assignment should have said something like "the initially larger number" or some such. Heh. :$

Duoas 1,025 Postaholic Featured Poster

Yoinks!

p.s. If you want a challenge, try implementing some of the standard C library. printf in particular is a bear.

Eh, it's not that bad. Just one big loop and a lot of branches.

I actually implemented sprintf in scheme. You wouldn't believe how many compilers get it wrong in spots. It was kind of fun, actually... ;)

Duoas 1,025 Postaholic Featured Poster

Hmm, if you say so. The program specification appears to read the other way to me. You might want to check with your professor to be sure.

It looks like you have got good function names. All the interesting stuff happens in process, so concentrate there.

Good luck!

Duoas 1,025 Postaholic Featured Poster

Your example is contrived, so just stick the shellcode in your first program as a function.

An overflow attack works by contaminating the code segment with data. For example, if I say:

void do_something() {
  char s[ 12 ];
  printf( "Enter a string> " );
  gets( s );
  printf( "The string you entered is \"%s\", s );
  }

The vulnerability is that the user may enter more than eleven characters before hitting ENTER. (Which is why gets() should never be used.) An attacker recognizes that after twelve characters he can insert executable code, so that the next time do_something() is called then what it actually looks like is this:

void do_something() {
  char s[ 12 ];
  <attacker's code here>
  ...

If you compile two separate programs you will have to find and get the actual 'attacker' code out of your second program. Skip the grief and just use debug.exe to turn your assembly into opcodes you can insert, or if you are going to play exclusively with C, just make the 'attacker' code another function.

Also, remember that exploiting this vulnerability always corrupts and/or destroys the attacked program, often leading to a crash. The attacker's goal isn't to be invisible, just to get his code executed at least once. That code can do anything the attacked program was privileged to do.

Also remember that this is a very simple example. A true attacker must be a bit more sophisticated than this. True attacks are wickedness and evil, …

Duoas 1,025 Postaholic Featured Poster

Since no one has answered this...

In a normal branch, the branch test is performed and the next opcode fetched depends on the result of the test. It might be the next opcode or it might be the opcode at the address indicated by the branch.

The net result is that the next opcode to actually be executed is not fetched until after the branch test is performed. This breaks the rhythm of the processer's fetch-execute loop, meaning that time is wasted.

A delayed branch tries to speed things up by fetching (and sometimes executing) a certain number of opcodes following the branch opcode regardless of the test result.

For simple tests this can speed things up a little, and when working with assembly instructions every little bit counts.

In order to avoid nasty side-effects, the assembler will typically insert a requisite number of no-ops after the branch opcode.

Duoas 1,025 Postaholic Featured Poster

It isn't working because you have not obeyed my advice. The user can hit enter a zillion times and it won't make any difference as long as you are using cin >> newfile; .

Also, notice how most of the lines you have written are exactly the same. Put all the stuff that writes to file by itself, once, after the file is opened using your if...else statement.

Duoas 1,025 Postaholic Featured Poster

Actually, I've answered your question quite thoroughly. You have to think now. I'll not do your homework for you. If I did, you wouldn't learn anything.

Narue commented: Good. +18
Duoas 1,025 Postaholic Featured Poster

First: Only include stuff you need. Go ahead and get rid of everything except iostream. (You don't use any I/O manipulators, you don't use any C math functions, you don't read or write to files, and you don't use any std::strings.)

Second: This point probably isn't obvious at first glance, but you should be using int instead of double. All the math taking place is integer arithmetic and all the example output lacks fractional parts.

Third: "Write a program using functions". You are missing functions (well, besides main). Try to divide your program up into simple functional parts:

main(): in a loop, call a function that asks for two numbers and does the assignment stuff, then ask the user if he wants to do it again. If not, quit the loop and quit the program.

functionA(): ask two numbers from the user. In a loop, complete the assignment's 'accumulator' stuff. Print the results.

functionB(): do the stuff that actually modifies the accumulator...

Make sure to come up with better function names than i've given you here. Also, don't use global variables. Make the functions take arguments and return values.

Finally: You need to get out a piece of paper and clearly write down the exact actions that the functionB() takes for each possibility. The accumulator will be modified one of two ways based on whether or not the larger number is odd or even. Do this and you'll breeze through this assignment.

Duoas 1,025 Postaholic Featured Poster

I'm afraid I've never used the trayicon component, but a lot of these inject code into your application's or main form's constructor. Make sure that isn't happening.

If the problem is one of MDI then you'll have to wait until I mess around with it to figure out why...

(I use my Delphi 5 IDE for everything. Best IDE ever as far as I'm concerned...)

Give me a day or two and if you (or someone else) haven't figured it out by then I'll post a more comprehensive response.

Sorry I couldn't be of more help in the meantime...

Duoas 1,025 Postaholic Featured Poster

Dave Sinkula gave you the best advice, but with the fewest words.

What he meant is that there are only two numbers you need to remember every time the user enters a number: the smallest entered so far and the largest entered so far. Hence:

#include <cstdlib>  // the atoi() function
#include <limits.h> // INT_MAX and INT_MIN

int smallest = INT_MAX;
int largest  = INT_MIN;
int i;
std::string s;

while (true) {
  std::cin >> s;
  if (s.empty()) break;
  i = std::atoi( s.c_str() );

  if (i < smallest) smallest = i;
  if (i > largest)  largest  = i;
  }

std::cout << "The smallest number you entered is " << smallest << ".\n";
std::cout << "The largest number you entered is "  << largest  << "." << std::endl;

The smallest starts out with the largest possible int value, so whatever you enter as the first number is going to be smaller than or equal to it.

Hope this helps.

<edited to use simpler code>

Duoas 1,025 Postaholic Featured Poster

Sounds like you have to write a program that takes a user-supplied number (like $132.17) and turn it into cash.

This is an easy homework problem you should be able to do yourself. But here's a hint: start by subtracting the large denomination bills first and work your way down to pennies until your number hits $0.00.

Good luck.

Duoas 1,025 Postaholic Featured Poster

Er, this is the wrong place for such questions. This forum is for people progamming in C++.

A CD usually needs to have some formatting done to it before writing. Perhaps your software is complaining that it hasn't been prepared to write audio data to it?

Duoas 1,025 Postaholic Featured Poster

You used cout yourself in your original program. Somewhere at the beginning of your code you probably have a line like

using namespace std;

which teachers persist in teaching people.

The cout object belongs to the std namespace, which you make active with the using statement. I typed it explicitly just to show good coding practice...

Enjoy!

Duoas 1,025 Postaholic Featured Poster

Probably not. What you want to do borders on illegal.

For just a player, take a look at the mediaplayer component.

Good luck.

Duoas 1,025 Postaholic Featured Poster

I've not messed with MDI forms much, but when you create your mainform you have to modify some of the application's system window properties.

procedure FormCreate(...);
  begin
  exstyle := getWindowLong( application.hanle, GWL_EXSTYLE )
  end;

procedure FormShow(...);
  begin
  setWindowLong( application.handle, GWL_EXSTYLE, exstyle )
  end;

procedure FormHide(...);
  begin
  setWindowLong( application.handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW )
  end;

The exstyle should be a cardinal variable somewhere.
Now the window will not appear in the taskbar whenever it is hidden. If you never want it in the taskbar then forget the show and hide stuff and just set the exstyle to toolwindow in the create event.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Actually, I think I was thinking of Python or something. Either way, it is still a good rule of thumb, even in C++. There should generally only be a maximum of one place that catches all possible exceptions. Number of processors is immaterial... Alas.