Duoas 1,025 Postaholic Featured Poster

You'll need to check your compiler's documentation. If you are using gcc, you can compile with the -S (that's a capital S) option to test some assembly code and look for yourself:

char foo( char c ) {
  return c +1;
  }
int main() {
  return foo( 0 );
  }

Using gcc -S foo.c gets you an assembly file you can look to see how _foo works.

I think (but I'm not sure) that most compilers will push it as a machine word, and just use the low byte.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Yoinks! Your right! That first post was made 2 1/2 years ago!
jamshid, please don't go digging for old posts to reply to...

Duoas 1,025 Postaholic Featured Poster

Actually, it is the preprocessor: cpp. Modern preprocessors are a lot smarter than they used to be. They actually tokenize the input. By using the "traditional" cpp mode, where the strings are simply replaced by new text in the input stream, the code is transformed properly for this program. Remember: -_ becomes: --F<00||--F-OO--; Without that minus sign out in front of the underscore, the first condition is just: -F<00 , which is incorrect.

I use MinGW happily. If you go to their site on sourceforge, you'll get a huge list of weird file names, like: gcc-ada-3.4.2-20040916-1.tar.gz. The first part (gcc-ada) is the package name. The second part is the version number (3.4.2). The third part is the date the package was compiled. The last part (1) is the package type. And finally, of course, the file extension.

You'll need/want the following packages:
gcc-core
gcc-g++
mingw-runtime
mingw-utils
binutils
mingw32-make
w32api

Look for stuff in the "current" section first. Otherwise try to get the latest version. You want the package type to be "bin". It will either say "bin" or nothing. Don't get "src" or anything else... Download them all to C:\MinGW\. Unpack them. Some come as exe. Some as zip. Some as tar.gz. Once unpacked you can delete the files you downloaded. Add C:\MinGW\bin to your path, and you're good to go.

(Personally, I prefer to keep it in C:\PROGRA~1\MinGW, it works fine. However, some utilities can't handle spaces in …

Duoas 1,025 Postaholic Featured Poster

Sorry, I can't. I haven't a clue why...

But I suspect it is just to be logical. Remember, a class is just a blueprint --it doesn't actually create any data (it only shapes it).

So it can link to static data in the class structure, but that static data must be declared as such: an actual const object taking space in the data segment.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Both atoi() and strtoul() take char*, but the string class will give you a char* if you say: number = atoi( s.[B]c_str[/B]() ); (where s is a std::string).

You must have a really, really old version of DevC++. Why don't you go download the latest version? (Or at least update your STL)?

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I get the following output: -201 -16 3.141 Did you compile with gcc -traditional-cpp ?


The printf statement just uses as few characters as needed to work. 4. floating point number * -F since F is negative, make it positive. (4.0 * (-F)) is a float. /OO float division (since numerator is float) /OO float division


Enjoy.

Jishnu commented: You've helped me a lot :) +2
Duoas 1,025 Postaholic Featured Poster

No one here is going to give you something they had to pay for. Besides which, it's illegal.

There are plenty of free programming resources on the web you can use just as well as anyone else. Here's a good place to start.

Duoas 1,025 Postaholic Featured Poster

It shouldn't work on XP either.

You've declared "numb" as a pointer to characters, but there aren't actually any characters being pointed at.

Question: why are you using a char* anyway? Use the STL string class:

#include <iostream>
#include <string>
using namespace std;

int main()
{
  string s;
  int number;

  cout << "Enter a number in 1-10 ";
  cin >> s;
  ...
}

If you want to convert a string to a number, you should use the STL stringstream:

#include <sstream>
...
  stringstream ss;
...
  ss.str( s );
  while (!(ss >> number) || ((int)ss.tellg() != (int)s.length()))
  {
    cout << "Try again: ";
    cin >> s;
    ss.clear();
    ss.str( s );
  }
...

The second part of the condition protects against input like "42x". The stuff at the bottom of the loop resets the stringstream.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You can't initialize it inside the class definition.
Do this instead:

class Test
{
public:
    static const string MYARRAY[];
};

const string Test::MYARRAY[] = {"hello", "world"};

Have fun!

Duoas 1,025 Postaholic Featured Poster

Ah.

It's just a giant math expression.

If you want to see it in action why don't you write something that traces the values of the variables F and OO?

If you do, you'll see that it uses a cheap trick based upon the circular shape of the _-_ sequences.

Each line of the circle separates an expression.
Each _ becomes (essentially) F--; OO--; and each -_ that follows it on the line becomes F--; That's the first cheap trick. The second cheap trick is where the lines separate. You'll notice that the lines separate around the circumference of the circle. The physical shape of the program affects the calculation --that is, F is modified each statement, but OO is only modified once per line. The amazing crazyness is that the circular shape is itself an approximation of PI. If you were to change it to a square or any other shape it wouldn't work. You can add more _-_'s to get a more accurate approximation, but the shape must remain a circle. (In other words, as you increase the resolution of the graph, you increase the accuracy of the computation.)

More than this you'll have to think about it yourself. Good luck.

Duoas 1,025 Postaholic Featured Poster

Yes, "string" is a standard template class.

I always mix up the stream constructors. Your first post complained that the ifstream required a string, so I took that as right. But that's backwards. The ifstream constructor requires your filename to be a char*. So... use: ifstream ifData( filename.c_str() ); If that doesn't fix your 'system' problem, show me every place in your code where you use the word 'system'. If there isn't any, there is some other problem... alas.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

No. Do your own homework.

If you want help along the way, post what it is that is giving you trouble and we'll help.

Duoas 1,025 Postaholic Featured Poster

OK, here you go. (Don't use char arrays for strings.)

#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

string make_filename( int file_number ) {
  stringstream sfilename;
  sfilename << "Site_" << file_number << ".txt";
  return sfilename.str();
  }

int main() {
  int Ns;
  string filename;

  for (Ns = 1; Ns <= N_Tables; Ns++) {
    filename = make_filename( Ns );
    ifstream ifData( filename );
    ...
    }

  return EXIT_SUCCESS;
  }

If you are determined to use char arrays for your filename, then say: ifstream ifData( string( buffer ) ); Happy Thanksgiving.

Duoas 1,025 Postaholic Featured Poster

Exactly. Happy Thanksgiving to you too! :)

Duoas 1,025 Postaholic Featured Poster

You're not paying attention.

char student[ SIZE ][ COLS ];

for (int i = 0; i < COLS; i++) {
  char c = student[ 0 ][ i ];
  student[ 0 ][ i ] = student[ 1 ][ i ];
  student[ 1 ][ i ] = c;
  }
Duoas 1,025 Postaholic Featured Poster

> I was told to use pointers whenever possible
In C++ you should avoid both.

> i just don't know if a char pointer is possible.
Did you try compiling your code above? Did it complain about a char * ?

You can make a pointer to anything.

You'd be better off, though, using a std::string:

#include <string>
using namespace std;

string students[ SIZE ];

Of course, you have to keep track of how many students you actually have, and you can never have more than SIZE students.

You'd be best off, then, using a std::vector or std::deque:

#include <string>
#include <vector>
using namespace std;

vector<string> students;

students.push_back( "Jayne" );
students.push_back( "Ronnie" );
students.push_back( "Hannah" );

cout << "The students' names are:\n";
for (int i = 0; i < students.size(); i++)
  cout << student[ i ] << endl;

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You can't say:

int a[100], b[100];
a = b;

That doesn't make sense. You can't change the value of a.

What would make sense is what you said: "i want the character array to be swapped with it." In other words, you want to exchange the values in the two arrays. This will require a loop:

for (int i = 0; i < 100; i++) {
  int t = a[ i ];
  a[ i ] = b[ i ];
  b[ i ] = t;
  }

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Scheme (and other functional languages) don't look or work the same way as imperative languages like C. There is no such thing as (return [I]anything[/I]) in Scheme.

A lambda always looks the same way: ([B]lambda[/B] [I]arg-list[/I] [I]body-sexpr[/I]) So a function that, say, adds two numbers looks like: (lambda (a b) (+ a b)) It starts with the word "lambda". Next it has a list of argument names. Finally it has an expression that gets evaluated.

You can name things with the "define" function: [B](define add [/B](lambda (a b) (+ a b))[B])[/B] Every expression must always have the proper order.

To get the union of two lists, you need to use some recursion. You will also want to create another function to help.

Everything in Scheme is a list (or more properly, an s-expression). So you have to think in terms of how to do things to a list. The principle is always the same:

If I can do something to the car of a list, then I can do that something to the whole list.

As an example, suppose you want to count the length of a list. There are two cases to worry about: either your list is empty '() (length = 0), or your list is not empty. The length of the list is the number of times it is not empty... (a b c) not empty (1 time). (b c) not empty (2 times) (c) not empty (3 times) () empty
The …

Duoas 1,025 Postaholic Featured Poster

Between lines 51 and 52 you need to add return EXIT_SUCCESS; . (If you start your code blocks with the name of the language you are using, you get line numbers: [[I][/I]code=C++[I][/I]].)

Line 56: are you sure there is an argv[ 1 ]?
Line 57: are you sure there is an argv[ 2 ]?
Line 62: isn't that the same as if (argc == 2) ?
Line 90: you could just swap the numbers so that num1 < num2...

A few other notes. Choose C or C++, not both:
1. Use #include <cstdlib> 2. When dealing with boolean values, use the keywords true and false , so it is obvious that you are dealing with a boolean value and not an integer.
3. Likewise, when testing boolean values, say if (a[num1]) or if (a[num1] == true) 4. Stick lines 43..52 as the first thing in your main. (There are good reason's why, but I don't want to take the time to explain them all now...)
5. Use functions.
6. Old C people and those who don't know better like to have their students use const int foosize = 12000; and junk like that. That's really about the same thing as saying: #define foosize 12000 The better way is just to declare your array as bool a[1000000]; and use the sizeof operator to get its size later: for (int i = 0; i < sizeof( a )/sizeof( a[ 0 ] ); i++)

Duoas 1,025 Postaholic Featured Poster

It's just a giant math expression.

Why are you trying to learn programming by looking at programs that are specifically designed to be hard to understand?

Duoas 1,025 Postaholic Featured Poster

As long as you keep the sequence points intact and the two values are the same ordinal type then you can do it just fine: a ^= b, b ^= a, a ^= b; Remember though, the result of this expression is the final value of a.

Duoas 1,025 Postaholic Featured Poster

I don't know Lisp, but I do know Scheme. Write yourself a little recursive function that does the job. I would use an index into the string to keep the original string reference (instead of recursively operating on copies of substrings). When you run out of string, then you've found all the matches.

You might find the stuff at the CL Cookbook useful. Particularly the (search ...) function.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

That program computes an approximation of PI by computing its own area. If you want to get more digits out of it, write a bigger program. [ 1 ]

BTW. That one's been around for years. It's one of the oldest entries in the International Obfuscated C Code Contest .

Duoas 1,025 Postaholic Featured Poster

> I am not sure if this is needed or not, but most CSV files have a header record, which is essentially the names of the columns separated by commas. If you are parsing an actual CSV file, you will need to take that into account also.

That may be true for some, but the vast majority of CSV files in use have no such thing. Unlike something like an XML file, CSV files have no way to tell you what they contain. The reading program must know what to expect when reading any CSV. Even the assumption that CSV is textual data, or fields separated by commas or tabs, and other stuff, is entirely that, assumption.

If you like I'll dig up an old CSV parser I wrote that can handle anything and port it to C for you. (Remember, it can read and write any CSV file, but, again, you must know what that CSV file contains for it to be useful!)

Duoas 1,025 Postaholic Featured Poster

you writhing copy function.. in that function we should mantain the parameter as const bcoz before executing any context switch will occer that any thread can modify the members of that object...

? What are you talking about? (Threads? You should know better than to share objects across threads!)

and this copy function is provided by compiler... if your writing means your overwritting that function... internally it ll return the this pointer we no need to return the this pointer externally...

Now you've totally lost me. Are you talking about A( const A& a ) or A &copy() ?

"Internally" it does exactly what it says. this is a pointer to myself. *this is me.
If I return this I get another pointer to myself.
If I return *this I get another me.

Duoas 1,025 Postaholic Featured Poster

> Sorry for such a late reply!
Heh, don't worry about it. Sometimes I'll mull things over for a day or two before replying to a thread, just to make sure I give the most intelligent answer I can. When I just automatically hit the "reply" button is when I tend to get into trouble...

I understand about the " vs '. Your compiler is weird, as that's illegal Pascal. The proper way is to double the ' character.

There's a technical term for this but I can never remember it: global variables aren't evil. But they should be avoided. The reason has to do with "state complexity". Computers always do exactly what they are told. We humans have trouble remembering more than a few things at a time, though, so when we have a lot of global variables accessed by a zillion procedures, we can't keep track of what state the program is in at any given time. This is part of the problem you are having with your assignment: there's too much information to remember at once.

The point behind "modular programming" is to reduce the "state" to smaller units that don't depend upon each other. For example, your code currently requires each routine to be aware of which one of digit1, digit2, digit3 it can change at any given time. That's dangerous, because if you mix up the routines the wrong way then you clobber data that you need. You are better off …

Duoas 1,025 Postaholic Featured Poster

Please listen to WaltP and google it. Here's what Wikipedia says. You can find printf the same way.

Duoas 1,025 Postaholic Featured Poster

No, the whole point is that copy() returns an implicitly copy-constructed copy of *a. Hence, *a is completely out of the equation by the time push_back() gets its piece.

Again, this is assuming copy() returns either A or A& (consistent with the return *(this); line above).

And again, as AD said, if A has any deep data at all, this will still fail, because the data that the copies of *a point to is the same data that *a points to. Once you delete a the deep data disappears also, leaving all copies of *a pointing to invalid data.

Here's an example to play with.

#include <iostream>
#include <string>
#include <list>
#include <cstring>
using namespace std;

int counter = 0;

class A {
  private:
    char *deep_data;
    int count;

  public:
    A( bool make_me_deep ) {
      count = counter++;
      cout << "Constructor: " << count << " as " << (make_me_deep ? "deep." : "shallow.") << endl;

      if (make_me_deep) {
        deep_data = new char[ 1000 ];
        strcpy( deep_data, "Knight to C3" );
        }
      else              deep_data = NULL;
      }

    ~A() {
      cout << "Destructor: " << count << endl;
      if (deep_data) delete[] deep_data;
      }

    A( const A& a ) {
      // simulate default copy constructor
      deep_data = a.deep_data;
      count     = a.count + 10;

      cout << "copied " << a.count << " as " << count << endl;
      }

//    A copy() {
    A &copy() {
      return *(this);
      }

    void hello() {
      char *s;
      if (deep_data) s = deep_data;
      else …
Duoas 1,025 Postaholic Featured Poster

I usually find that there is a good reason, but in this case I can't see any reason to have those temporary variables, as they are unused in any other way. Perhaps they are just a relic when the original author was debugging the routine...

Also, this routine is amazingly cavalier about the state of the Direction Flag. There should be a "cld\n\t" at the front. (Check to see how it is used, first, before changing it though... I think the standard C library expects this to work in the forward direction though.)

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

"Yes."

Duoas 1,025 Postaholic Featured Poster

Sure. That works.

Duoas 1,025 Postaholic Featured Poster

I don't know where you got that code, but it is wholly ineffective. It uses the copy constructor whether you like it or not.

Further, you left the return type off of the copy() function (so it wouldn't compile). If you declare it as: A &copy(); then you'll wind-up with two copies of a. If you declare it as: A copy(); you'll produce three copies of a (one a temporary used in the assignment).

In all cases, the first a that you created with new still needs to be explicitly deleted. Otherwise you'll have a memory leak.

The problem with the default copy constructor that Ancient Dragon alluded to is that it makes a byte-for-byte copy of your object. If your object news variables, etc., then what you get using the default copy constructor is two objects that use the exact same data. So what happens if one object deletes that data? Then the other tries to use or delete it, and your program crashes.

If you want to read more on this, google "shallow vs deep copy".

BTW. Don't name lists "list" or arrays "array".

Oh, yeah, also. If you really want to just pass a pointer off, use a list of pointers:

list<A*> ls;
A *a = new A( ... );
ls.push_back( a );

This works just fine. Your object is never copied (the pointer to the object is copied). You still have to remember to delete each object in the …

Duoas 1,025 Postaholic Featured Poster

What you need to do is find a useful reference. I like cppreference.com, but it is rather curt.

In C++, you can easily append strings and characters, so you might try something like:

#include <iostream>
#include <string>
using namespace std;

string spacesToTilde10( string s ) {
  string result;
  for (int i = 0; i < s.length(); i++)
    if (s[ i ] == ' ') result += "~10";
    else               result += s[ i ];
  return result;
  }

int main() {
  string s;
  cout << "Please enter a string with spaces> ";
  getline( cin, s );
  cout << "I don't like spaces, so I changed your string to \""
       << spacesToTilde10( s )
       << "\". So there! Nyah!"
       << endl;
  return EXIT_SUCCESS;
  }

Like Salem said, there is no need to dink with a char array. Just use the stuff that std::string gives you.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Argh. Missed a key:

[EDIT] As an addendum, you should note that "is_it_even" works fine. That's because the scope inside the "is_it_even" function is inside that "oddstuff" unit. So is_it_even calls the correct is_it_odd function. [/EDIT]

Duoas 1,025 Postaholic Featured Poster

I almost missed this because your thread is marked 'solved'.

That last thing is so full of errors I don't think you've spent much time reading over your textbook or class notes. It certainly won't compile, and most pascal compilers are pretty explicit about where and what errors you have, and how to go about fixing them.

Try again.

Duoas 1,025 Postaholic Featured Poster

Eh, OK. Don't take this the wrong way, but you need to read some more on gaussian elimination using partial pivotization. Your code is missing loops where there should be loops, and where there are loops, you are indexing stuff you shouldn't.

BTW. I'm sure you know that the code you posted doesn't compile. I haven't tried, but right at the start I noticed two fatal errors.

First you assign c (an integer) an element of A (a real). Without explicit conversion in Pascal this will fail as a type error. Even so, the algorithm will not work over integers.

Second, you are using a variable named "i" which you never declared. In fact, I think you are being confused by the choices you have made in naming your variables.

Here is a rule that will help greatly:

Never use one letter variable names unless:

1. The name of the variable is "not important" AND you are using it in about ten lines of code or less.

By "not important" I mean that the meaning of variable itself is ancillary. For example:

procedure print_string( str: pchar; length: integer );
  var i: integer;
  begin
  for i := 0 to length-1 do write( str[ i ] )
  end;

While this is an obviously contrived example, it illustrates the point: the name of the variable "i" is unimportant because it is immediately apparent what the code that uses it does.

However, once you get into multiple loops, or multidimensional arrays, or …

Duoas 1,025 Postaholic Featured Poster

Hey there, just a heads-up to let you know that help is forthcoming. I just had to go learn how to solve a linear system of equations using gaussian elimination and partial pivotization first.

Now I'm looking over your code. I've got a few suggestions about commentary and variable names, but that will come when I post again.

Duoas 1,025 Postaholic Featured Poster

Google "delphi sockets" for help. You'll have to implement a few server/client programs (the same program can be both) that allows you to communicate. There is no limit to what you send over a connection (it looks much like a file stream when you use it). The trick is just to tell things apart.

You have embarked on a difficult task indeed. Good luck.

Duoas 1,025 Postaholic Featured Poster

I think you ought to go sit down with your professor and ask for some more details about how he wants you to solve the problem. If you ask correctly (professors, as all people, generally love to talk about their subject) you might get a lot more information than otherwise, which will help you figure things out. Don't let him push you out. It is his job to help you understand, so if you are still confused about something in particular, just say: "I don't understand why ..." or "If I understand right, I need to ...".

Good luck.

Duoas 1,025 Postaholic Featured Poster

Oy, after all that typing you beat me to the punch with another Q.

Second tutorial: scope.

Just as the functions and procedures above all belonged to tMatrix, so do the variables. Remember how you can do something like:

program McGonagalls_notes;
type
  tStudent = record
    name: string;
    grade: integer
    end;

var
  my_student: tStudent;

begin
  with my_student do
    begin
    name := 'Hermione Granger';
    grade := 100
    end
end.

Professor McGonagall remembered that when she is only thinking of one particular student, she doesn't need to remember all the information about where or how the student is referenced --she can just concentrate on that particular student. If she had preferred, she could have just said:

my_student.name := 'Hermione Granger';
my_student.grade := 100;

It is the exact same thing, but written using different scoping rules (by using the with statement).

The scope is what you can see at the moment. In an earlier example I created a unit to return whether a number is odd or even. Now, consider the following:

program oddness;
uses oddstuff;

procedure is_it_odd( n: integer ): boolean;
  begin
  result := FALSE;
  end;

var x: integer;

begin
  write( 'Please enter a whole number greater than zero> ' );
  readln( x );
  writeln( 'The statement "', x, ' is odd" is ', is_it_odd( x ), '.' );
  writeln( 'The statement "', x, ' is even" is ', is_it_even( x ), '.' )
end.

Now, the question is, "Which is_it_odd function gets called? The one in the unit or …

squidd commented: very well written and helpful +1
Duoas 1,025 Postaholic Featured Poster

Ah.

The difference is whether the function is a method of the TMainForm class or not.

A quick tutorial:

Forward declarations vs. automatic declarations

Normally you might have a program that looks like this:

program foo;

function triple_it( x: real ): real;
  begin
  triple_it := x *3
  end;

var
  number: real;

begin
  write( 'Please enter a number to be tripled> ' );
  readln( r );
  writeln( r, ' tripled is ', triple_it( r ) )
end.

In this little program, we have both declared and defined a function named "triple_it". By declaring, we mean that we have told the compiler that it exists. By defining, we mean that we have told the compiler all the details about it. Typically, as in this example, things are declared at the same time they are defined. That is, by defining a thing we implicitly declare it as well.

In Pascal, a thing must be at least declared before it is used.

Sometimes, however, we need to tell a program that something exists before we actually define it. Hence, we need to use a forward declaration. Here's a simplistic example lifted off of the Wikipedia (and repaired for correctness):

program oddness;

function is_it_even( n: integer ): boolean; forward;

function is_it_odd( n: integer ): boolean;
  begin
  if n = 1
    then is_it_odd := TRUE
    else is_it_odd := is_it_even( n -1 )
  end;

function is_it_even;
  begin
  if n = 1
    then is_it_even := FALSE
    else is_it_even := is_it_odd( n -1 ) …
Duoas 1,025 Postaholic Featured Poster
with Ada.Text_IO;

procedure Answer is
  use Ada.Text_IO;
  begin
  Put_Line("Sure.");
  end Answer;
Duoas 1,025 Postaholic Featured Poster

What you have written looks right. But just to make sure you got there correctly (which makes all the difference):

1. You added a button to your form and named it "ReverseOrderButton".
2. You either a) double-clicked the button on your form, or b) changed the object inspector to list events and double clicked the "OnClick" item
3. You added your code.

Yes, it does something. However, in the example posted you reverse an uninitialized local string. That is, a string that only exists in the ReverseOrderButtonClick function and which you did not s := "hello"; before reversing, and which you have not displayed before the procedure quits and the string disappears. So, while you have reversed the string '', it never gets displayed and it appears that nothing happens.

Try this to see what it does:

procedure TMainForm.ReverseOrderButtonClick( Sender: TObject );
  begin
  with ReverseOrderButton do
    Caption := StringReverse( Caption )
  end;

The same is true for any Item[ x ].Caption .

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Brilliant.

I'm going to pick. The way your code looks is a tremendous help to understanding.

program eight;
uses crt;

var
  stop       : integer;
  posinteger : integer;
  sum        : integer;

begin
  sum := 0;
  writeln('Enter a positive integer, 0 to quit');
  readln(stop);
  while stop <> 0 do
    begin
    posinteger := stop mod 2;
    readln;
    if posinteger = 0
      then writeln('This number is even')
      else writeln('This number is odd');

    sum := sum + stop;

    writeln( 'Press ENTER to continue' );
    readln;

    clrscr;
    writeln('Enter a positive integer, 0 to quit');
    readln(stop);
    end;

  writeln( 'The sum of all the numbers you entered is ', sum );
end.

You'll notice I made a couple of minor changes. First, I told the user (who might not be you) what he is expected to do to continue when the program pauses. Also, you had defined a variable "sum" which didn't do anything. I made it do something.

Enjoy! :)

Duoas 1,025 Postaholic Featured Poster

Watch your condition flags. ADD modifies the flags register just as much as CMP does. So you only loop above if SI is not zero...

Also, the last two lines never get called...

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

BASIC is a high-level-language. Assembly is not. You can't think like BASIC in assembly.

BASIC actually has a named variable somewhere in the data segment. When you say PRINT "something" it first copies the string "something" over to the variable in the data segment, then prints that, basically like I showed you above. (In reality, it is a bit more complex than that, because of the way BASIC stores data in the data segment, but the essentials are the same.)

Duoas 1,025 Postaholic Featured Poster

Sounds like you are asked to do something repetitively, so that suggests using a loop. Post some code and we'll help further. (You should be able to do this on your own.)

Duoas 1,025 Postaholic Featured Poster

You are thinking in C. Don't put anything after the end. (that's "end" with a period after it). A program looks just like a giant procedure, with subroutines (procedures and functions) in it.

Did your professor tell you how he expects you to store your equation in an array? Or give any direction on how to solve it?

Duoas 1,025 Postaholic Featured Poster

I'm sorry, but you'll need to think on that one yourself for a bit. I can help once you write some code... for a hint, how would you do something like the following:

Write a function that takes a string (an array of characters) composed of the digits '0'..'9', turns it into an integer, and returns that integer value.

For example:

var i: integer;
begin
  i := str_to_int( '42' );
  writeln( 'Converted the string "42" to the integer ', i )
end.

Once you have done that, modify your function to return real values:

var x: real;
begin
  x := str_to_real( '3.141592' );
  writeln( 'Converted the string "3.141592" to the floating point value ', x:0:6 )
end.

If you can break your code up into simple problems then all you have to do is solve a bunch of simple problems instead of one big problem. You'll have to do that to complete this assignment.

Once you have some code going, post here with specific problems for more help. Good luck. (And have fun!)

Duoas 1,025 Postaholic Featured Poster

> Try one then the other is not a portable solution.
How so? It works on both systems! (It most certainly is a cheap kludge! That's not the point. The point is that it works.)

Your list of OSes is considerably short. You are absolutely right: my wording was off and I've not expressed myself clearly. I mean that most of the people posting here are using systems that it would work on. Those that aren't know better, because of the very fact that it isn't Windows or some Unix derivative. I will try to be more explicit in the future.

vijayan121
Wait... you mean you want to write a console program that knows how to interact with other programs in a GUI system? Good luck with that.

If you want to use the mouse and create text menus and other windows within your console application then that is quite frankly what curses was designed for. Go read the docs again. You'll recall that console programs aren't designed to have any clue about each other. That's traditionally been the OS's job. You can't give me a hard time because your console program doesn't know how to respond like a windows program.

Using the mouse is always a system-specific thing. Just like using the flaming keyboard and display. Hence the purpose of libraries like curses. I know PDCurses works well and that it covers nearly every platform curses and ncurses does (plus some they don't). …