Duoas 1,025 Postaholic Featured Poster

Oh. For that just say:

cin >> userInput;
if (!cin) {
  cout << "NOTHING TO PROCESS\n";
  break;
  }

This still trips if you enter something other than an integer, but to be more specific means you'd have to read the input as a string then convert it to an integer. Ask your professor if he would rather you read input as a string or as an integer.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Sorry, I should have made myself more clear.

Try this:

procedure TMainForm.RemoveDuplicatesButtonClick(Sender: TObject); 
  var
    i, j, num_removed: integer;
  begin
    num_removed := 0;
    for i := 0 to ListView1.Items.Count - 1 do
      for j := ListView1.Items.Count-1 downto i+1 do
        begin
        if i = j then continue;  // <-- this line shouldn't be necessary
        if ListView1.Items[i].Caption = ListView1.Items[j].Caption then
          begin
          ListView1.Items.Delete(j);
          inc( num_removed )
          end;
        Application.ProcessMessages;
        end;
    ListView1.Columns[0].Caption := inttostr(ListView1.items.Count);
    CurrentStatusLabel.caption := 'Removed ' + inttostr(num_removed) + ' Duplicates';
  end;

I didn't actually test this code --it's late and I'm going to bed now... Also, with the revised j loop I don't think you need to test for i = j, it should never happen. (Alas, my brain is shot right now...)

Good luck.

squidd commented: Always an enormous help to me and has never given up in his efforts to help me. No amount of thanks descirbes my appreciation for this individual! +1
Duoas 1,025 Postaholic Featured Poster

You need to think a little bit more about what you are doing. The file you are supposed to be reading is "fooey.txt" --specified when you created the FileString class. It doesn't have to be "fooey.txt" --it could be "edata.dat" or "myprog.cpp" or whatever, but you are supposed to tell it the filename when you create the class in main.

Also, why are you reading from a file in the value() method? (Watch your syntax. Since you defined value() outside the class { and }, you must prefix the name with the class name.)
You should not be opening or reading any files in value(). Remember what was said about c_str(). Also, what is 'buffer' for? Think about these things.

Lastly, your red line was my fault. istream.read() takes exactly two arguments and I used only one. It should say fs.read( text, endposition ); Sorry about that.

You should find a convenient reference you can use to look stuff up when you find errors. I like cppreference.com, but it is rather simplistic. There are others. Find one you like and use it religiously.

Get some sleep. ;)

Duoas 1,025 Postaholic Featured Poster

A std::string is just a fancy way of handling a c-string. So yes, you are getting the c-string out of it.

There is no way for you to know how many lines there are in the file, not until you read every line in the file, that is.

I don't know why you are dividing the file size by your FileString class's size (which, for all intents and purposes, you should consider as a random number). The length of the file is endposition. (Remember how I got the length of the file in post #4?)

Lines in a file are separated by newlines. On Unix, that's '\n'. On Windows, that's "\r\n". On a Mac, that's '\r'. It doesn't look like your teacher is interested in individual lines in the file. He just wants the whole thing in one string.

Your FileString class should have a method prototyped: const char *value(); which gets you the string (the whole file) that you read. (This is the same thing that std::string.c_str() did.)

You should be able to use your class like this:

int main()
{
  FileString f( "fooey.txt" );
  cout << "The file's contents are:\n"
       << f.value();
  return EXIT_SUCCESS;
}

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Ah, that's easier. Just loop until userInput < 0 .

while (true) {  // do loop forever
  // get input here --> userInput
  if (userInput < 0) break;  // quit if user gives a neg num
  // do the min/max stuff here
  }
//print the min/max here

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

The TListView is going to be really slow no matter what. However, there are a couple of things you can do to help.

In your loop on line 9, you are starting at zero again. You don't need to check things already known not to be duplicates. Say instead: for j := i+1 to ListView1.Items.Count-1 do In the same vein, when you goto recheck you are starting all over. Since the items are ordered, you might want to work backwards: for j := ListView1.Items.Count-1 downto i+1 do When a duplicate is found and removed, you just continue on your merry way and ignore all the stuff you have already checked (and possibly removed).

You might want to consider using the ListView1.FindCaption method instead of the doing the inner loop yourself. That way you can just loop until FindCaption returns nil. I think that would probably add a time savings since the class can usually access its members faster than you can using the classes property accessors.

You can count how many you removed by incrementing a counter whenever you actually remove a duplicate and at no time else. Set the counter to zero before you do anything else. I'm sure you had something very close to this when you tried before.

Good luck.

Duoas 1,025 Postaholic Featured Poster

You have two problems:

1. Add a break statement after you set i to zero:

void validate_name(string &name)//validate_name for each student
{
	int i;
	for(i=0;i<(name.length());i++)
	{
		while( !(isalpha(name[i])) && !(isspace(name[i])) )
		{
			cout<<"Enter correct Name of student ,please:\n";
			getline(cin,name);
			i=0;
			break;
		}
	}
	
}

2. You need to get that last newline you left in the buffer after getting the year.

...
cin>>d>>m>>y;
cin.ignore( 10000, '\n' );
...

The trouble happens because you are mixing >> with getline().

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

What type of thing is userInput?

Duoas 1,025 Postaholic Featured Poster

For code blocks. It is watermarked behind the text edit you get when posting.

Windows was written in C. Its API is in C. Every bit of your code is C. Most C++ compilers have windows header files (like <windows.h>) set up so that they can be use by both C and C++ programs, so even if you are compiling with C++ you are still only using C.
Since you have not used any C++ at all, I assumed that you were using C.

I know what the hell WinHelp is. I use it every day. I also have just about every piece of documentation about windows and the Win32 API. I suspect I have a fair deal better idea what is in there than you do. Further, I'm no C++ weenie. If you want help, you might want to consider that the people responding might know something about how to use the language.
If you had followed my instructions your compiler wouldn't have complained about &bmi. You have created a pointer to something, but that something does not exist. Until you create it, it never will. For what you want to do, you do not need to use a pointer.

The CreateDIBSection() function only allocates memory for the pixel data. It will not allocate your BITMAPINFO structure. Rather, it expects you to have one already, which it uses to properly allocate your pixel data.

Finally, I know something about C/C++ compiler …

Duoas 1,025 Postaholic Featured Poster

You need to #include <iomanip> and add setw() and setfill() to your output statements.

Something for James Bond: cout << setfill( '0' ) << setw( 3 ) << 7; Hope this helps.

[EDIT] Oh yeah, if you think your numbers might be negative, use the internal flag: cout << setfill( '0' ) << internal << setw( 4 ) << -42;

Duoas 1,025 Postaholic Featured Poster

Yes. A card is a single object. If you want a list of cards, then store a list of cards, not a list of suits and ranks.

(define dead-mans-hand (list
  (make-card 13 'spades)
  (make-card 13 'clubs)
  (make-card 8 'spades)
  (make-card 8 'clubs)
  (make-card 2 'hearts)
  ))

Thereafter, you can get, say, the second card's suit with: (suit (second dead-mans-hand)) Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Sorry. I always forget that the stupid fstream constructors don't take std::strings.
Say: fstream fs( filename.c_str(), ios::binary ); instead.

You could have looked this up yourself.

Duoas 1,025 Postaholic Featured Poster

Eh, OK.

When people ask for clarification, it is not usually very helpful to re-post what you already said, as if we're stupid.

I will assume by the added comment

both arrays in which i will place the text from the text file. "registers" will get the first 8 lines of numbers and memory will get the remaining lines of numbers

that you mean you want to skip everything in the file until you find a number, because the file has no structure.

I also am going to assume that each line in the file contains a single value.

Your best bet, then, is to get each line, then parse it to see if it is a number. If it is, store the number. If not, keep going.

...
#include <sstream>
...
...
int registers[ 7 ];
int memory[ 4000 ];
int i;
string s;

// read registers until eight integers are read
i = 0;
while (getline( in, s )) {
  if (stringstream( s ) >> registers[ i ]) i++;
  if (i == 8) break;
  }

// read memory until the end of file
i = 0;
while (getline( in, s )) {
  if (stringstream( s ) >> memory[ i ]) i++;
  }
in.close();
...

I hope this helps.

Duoas 1,025 Postaholic Featured Poster

I have no clue why that code shouldn't work. However, you should be opening filename instead of "newfile.dat".

You have no string buffer defined in your class. If you want to use it, you must first define it. Then you can test for error like you want:

class FileString {
  private:
    string buffer;
  public:
    FileString( string filename ) {
      fstream fs( filename, ios::binary );
      if (!fs) {
        buffer = "**ERR: could not open file";
        return;
        }
      // otherwise, read the file
      fs.close();
      }
  };

Good luck.

Duoas 1,025 Postaholic Featured Poster

You have not done what I have asked you. I don't know how you got that last code, but it is not going to help you at all. It doesn't do anything that relates to your original question.

Get the length of a file (in bytes) thus:

istream f( "foo.txt", ios::binary );
f.seekg( 0, ios::end );
unsigned long length = f.tellg();

You can then allocate space to read the file:

char *text = new char[ length +1 ];  // don't forget the null-terminator

And you can read it all at once:

f.seekg( 0 );
f.read( text );
text[ length ] = '\0';  // don't forget to terminate the string

Both seekg() and tellg() are listed in the (short) list at the link I gave you, and are the only methods that tell you where in the file you are.

Duoas 1,025 Postaholic Featured Poster

Your code and your input file don't match. I cannot tell which things you are trying to put where.

Please try to explain what goes where and I will try to help.

Duoas 1,025 Postaholic Featured Poster

Please, please, use [[I][/I]code[I][/I]] blocks to post. Anything else leaves unreadable and difficult to cut/paste stuff. Also, this is the C++ forum, not C.

You misunderstand a few basic concepts.

1
Anything with const in front of it cannot be modified. You don't need it here, especially since you intend to modify the value (after all, you want to create a bitmap you can edit in memory, right?).

2
Anything that looks like foo *bar; creates a pointer to something. That something doesn't exist until you use malloc() to create it. In this case, you don't need it to be a pointer. Just say:

BITMAPINFO bmi;

Since the BITMAPINFO structure contains a BITMAPINFOHEADER, there is absolutely no need to create another.

3
Anything that looks like foo bar = baz; is a variable declaration and a variable assignment combined into one. That is, it is equivalent to the two statments: foo bar; (Create a variable named "bar" of type "foo") bar = baz; (Assign the value "baz" to the variable "bar")
You need to say:

bmi.bmiHeader.biSize  = sizeof( BITMAPINFOHEADER );
bmi.bmiHeader.biWidth = 340;
...

This begins assigning values to the various fields inside the BITMAPINFOHEADER struct of the BITMAPINFO variable.

4
CreateDIBSection() does not create a file. It creates a bitmap (in memory). If you want to write the bitmap to file, I recommend you to this article I googled.

5
Watch the types of …

Duoas 1,025 Postaholic Featured Poster

>The program actually compiles if I use " instead of '. It actually doesn't compile if I use ' instead.
Sorry to address this first, but whaaat???? What compiler are you using? If it doesn't take ' but does take " then there is something seriously wrong. ' is Pascal. " is not. Never has been. Never will be.


OK, on to your real problem. :-/

Your loop is predicated upon something that never changes in the loop: legalinteger. The order you do things is also a little disorganized. Presumably you know that c is a digit when you first call convert. However, once you start the procedure, you read another c from the file and assume that it also is a digit. Don't. All your reads should be inside the loop.
Your loop should also be carefully structured so that you do not multiply digit1 by ten unless you already know that the next c is a digit.


Also, I think your professor is a crazy loon. So that's why you are using so many global variables and non-separable procedures. Would he concede to let you pass by reference? procedure fooey( var i: integer ); What you are doing is learning to program badly. There is no better way to say it. If this is really what your professor wants I think he should be fired.

[EDIT] Caught your last post. The edit button disappears once you log out.

Duoas 1,025 Postaholic Featured Poster

You can go backwards through a loop using the downto keyword:

procedure writeln_backwards( s: string );
  var i: integer;
  begin
    for i := length( s ) downto 1 do write( s[ i ] );
    writeln
  end;

Enjoy!

Duoas 1,025 Postaholic Featured Poster

Have you looked at Wikipedia?

You really haven't given us much information to work with. "An array representation" can mean many, many different things.

Post us the code you have so far and we'll help you fix it.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Erm, stacks and queues are very useful, very basic, and very well-used data structures. To clarify what mohanrobin said:

For a stack, you have a list that you can add items to and remove items from, but only to or from the end (or "top") of the stack.

A queue is basically a stack, except that you can add and remove items from either end.

So it is fairly easy to implement one in terms of the other. Why don't you post some code and/or homework requirements and we'll see if we can't help you further.

[EDIT] BTW. There are "similar threads" down at the bottom of the page that list a whole bunch of stuff about stacks and queues in C.

Duoas 1,025 Postaholic Featured Poster

Listen to Salem. C does not have a vector anything. Nor does it have generic anything. Those are both C++ constructs.

Duoas 1,025 Postaholic Featured Poster

Don't say int main( void ) either. The main() function actually does take arguments... but if you don't want to deal with them use C++, not some bad C abomination: int main() When in Rome, do as the romans. When using C++, use C++ I/O.

Don't use getchar() (or any of the non-standard variations). Use std::cin.get() instead.
Don't use fgets() (or, *gasp*, gets()). Use std::getline() or std::cin.get() instead.

Duoas 1,025 Postaholic Featured Poster

Why don't you show us some [[I][/I]code[I][/I]]?

Duoas 1,025 Postaholic Featured Poster

There are no procedures in scheme, only functions. Whenever you say define, you are naming an expression that evaluates to something.

Hence, follow along: (a-card 13 'spades) becomes (make-card 13 'spades) becomes (list 13 'spades) becomes '(13 'spades) The make-card and a-card functions do the same thing: take a rank and suit and return a card. Why not get rid of one of them?

I think you need to re-read your class notes about the difference between a list and a pair.

Personally, I would store the card as a pair: (define make-card (lambda (rank suit) (cons rank suit))) Or, using the shortcut syntax: (define (make-card rank suit) (cons rank suit)) Now, you know that a card is a pair of '(rank . suit), so to get out the rank or suit you only need a new function get knows what a card looks like: (define (rank card) (car card)) (define (suit card) (cdr card)) The purpose is to make it so that no one knows that a card is just a pair (or a list or something else). You know, because that is how you are storing it. But anyone else using your program only needs to know three functions: make-card rank suit : return a card object rank card : return the rank of a card object suit card : return the suit of a card object

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I haven't examined you algorithm very deeply, but somewhere in changeBoard() you are accessing an element outside of the board array. The error is recorded on the stack (the board is also stored on the stack), but only noticed when you try to return from main().

Duoas 1,025 Postaholic Featured Poster

Well, you could always take it the semester after next... But I recommend that you not skip it. However, what I think is not necessarily what is best for you. Go make an appointment to talk with the head of the CS department and he'll be better able to help you work out a schedule that satisfies your goals.

Duoas 1,025 Postaholic Featured Poster

Any time you can group objects together into a single 'class' of thing you can use polymorphism. The concept behind COM objects are an example. Objects in a video game. Elements in a Raytracer (mesh, camera, curve, etc., materials, etc.). You can come up with all kinds of examples on your own.

Duoas 1,025 Postaholic Featured Poster

Data structures are central to programming. (A C++ class is a data structure.)

What level class is it? If it is lower than your C++ class then you might be able to skip it, but if it is only 100 or less points lower then you should consider it.

All network programming is performed by using a protocol to transmit structured data. (The deeper you get, the more you realize that data is code is data.)

Duoas 1,025 Postaholic Featured Poster

The overhead isn't so great as everybody goes on and on about. However, you should only make virtual those functions which need to be virtual. Typically only public and some protected methods are virtual, while private and some protected methods are static.

Duoas 1,025 Postaholic Featured Poster

Sorry, I had just answered some questions in the C++ forum and forgot that this was the C forum, so a deque is unavailable in C...

Yes, the chdir() function can take both relative and absolute paths.

For parsing the paths I recommend you to the strpbrk() or strchr() functions (both defined in <string.h>).

Good luck.

Duoas 1,025 Postaholic Featured Poster

An overloaded function is a function that shares its name with one or more other functions, but which has a different parameter list. The compiler chooses which function is desired based upon the arguments used.

An overridden function is a method in a descendant class that has a different definition than a virtual function in an ancestor class. The compiler chooses which function is desired based upon the type of the object being used to call the function.

A redefined function is a method in a descendant class that has a different definition than a non-virtual function in an ancestor class. Don't do this. Since the method is not virtual, the compiler chooses which function to call based upon the static type of the object reference rather than the actual type of the object.

For example, if you have an Animal *george , and george = new Monkey; , where Monkey inherits from Animal, if you say george->dosomething() the Animal.dosomething() method is called, even though george is a Monkey (even if a Monkey.dosomething() method is available).

Good luck.

Duki commented: Well said. Really helped me to put concepts into words. Thanks! +4
Duoas 1,025 Postaholic Featured Poster

Not really. It is about as simple as it gets. You'd have to add a bit of complexity to make it less brute force, and for what you are doing it isn't worth the effort.

Good job, BTW.

maxmaxwell commented: He was a great help in helping get my problem solved +1
Duoas 1,025 Postaholic Featured Poster

Alright. Try this:

int show_grid()
{
  cout << "    1  2  3  4\n"
       << "  +------------\n";
  for (int x = 0; x < 4; x++)
  {
    cout << setw( 2 ) << y << "| ";
    for (int y = 0; y < 4; y++)
      cout << card_value[x][y] << "  ";
    cout << '\n';
  }
  cout << endl;
}

You might want to add a little if statement in the center loop to check whether you are supposed to print the card value or a '*'.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

User supplied file names must be either absolute or relative to the application. If the file starts with '/' then it must be absolute. Otherwise, it is relative. Just tack it on to the end of the current working directory name, then collapse instances of "./" and "../".

You didn't say whether you are working on Unix or Windows, so you should be able to handle paths that start with a drive letter ("D:/foo/bar" is absolute, but "D:foo/bar" is relative) and that use '\\' and/or '/' as separators.

Personally, I would be inclined to split the path into a deque, manipulate its parts, then join it back together when done.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

That does sound odd. Can you post:
1. an example of the file
2. examples of what you are seeing in windows and in linux
3. the code you are using

A cue file is a text file, no? Why are you using fread() instead of something like fgets()?

Duoas 1,025 Postaholic Featured Poster

You need to pull out your textbook and look at some sample programs. Watch your syntax.

Whenever a professor says "hint" that's a good place to start. I see you have one 2D array for the card values. You still need a 2D array for whether or not the card is face up.

Here are some suggestions from me:
1. Your fill_values function is a good start, but needs help. The prototype should be: void fill_values( int &card_value[4][4] ) . Don't cout anything, and don't return anything.

2. Make a similar function that shuffles the cards like your professor hints: void shuffle_cards( int &card_value[4][4] ) . This function does something repeatedly (selects two cards at random and swaps their values). This suggests a loop. It doesn't matter how many times through the loop you go as long as it is sufficient to shuffle the cards. 100 to 200 times ought to do it. (Also, I don't understand the comment about the random number generator. If you want to do something randomly you must use a random number generator.) Since your cards are stored in a 4 x 4 matrix, you'll need four random numbers each time through the loop: two for each card to swap: a y in [0..3] and an x in [0..3].

3. Make a similar function that initializes all the cards displayed states: void fill_visible( bool &cards_visible[4][4] ) When the game starts they should all be invisible (or face-down).

4. Make …

Duoas 1,025 Postaholic Featured Poster

Read more carefully. Since the "1|" is going to push your display no matter what, just push the top line the same amount with a couple spaces.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I'm sorry. I goofed twice. It should read: cin.ignore( 10000, '\n' ); That'll fix it.

Duoas 1,025 Postaholic Featured Poster

Yes, your comment is absolutely right. Placing something at the beginning of the line will absolutely cause anything else on the line to be shifted rightward.

Since your lines have fixed spaces fore and aft of each card, why not add a couple of spaces to the "header" line that numbers the grid?

// Instead of:
cout<<"    " << "1       2       3       4  " << endl;
// Use:
cout<<"      " << "1       2       3       4  " << endl;

(Notice how I added two spaces to account for the "1|"?)

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Oop! You're right. The first doesn't throw an exception...

He'd have to test the first the same way: if (!(cin >> rating[ i ])) fooey(); The second only throws an exception because I threw it after testing the stringstream for the error state the same way...

Duoas 1,025 Postaholic Featured Poster

Glad to be of help. Just don't forget to delete things when you are done with them.

Duoas 1,025 Postaholic Featured Poster

What he means is don't use cin >> myvar; alongside cin.get( mystring ); The problem comes because doing so breaks the user's input model. When you ask for something, the user types an answer and presses ENTER. The get() method returns the string entered and tosses the ENTER away. The >> method only gets the first thing the user typed and doesn't toss anything away.

You can fix the problem one of two ways:

// fix #1
cin >> rating[ i ];  // try to read an integer
cin.ignore( 10000 );  // ignore everything else and toss the ENTER
// fix #2
#include <sstream>
#include <exception>
...
string s;
...
cin.get( s );  // read everything
if (!(stringstream( s ) >> rating[ i ]))  // then convert to an integer
  throw runtime_error( "Not an integer!" );  // complain if not an integer

Both methods throw an exception if you try to enter something other than an integer. The second method is a tad easier to look at if you want to deal with the error...

Duoas 1,025 Postaholic Featured Poster

You can split the string into tokens using the stringstream class:

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

int main() {
  string s;
  stringstream ss;
  vector<string> v;

  cout << "Please enter a string to be separated by tab characters:" << endl;
  getline( cin, s );

  // Convert the line of text into a list of tokens
  ss << s;
  while (getline( ss, s, '\t' )) v.push_back( s );

  cout << "The tokens are:\n";
  for (int i = 0; i < v.size(); i++)
    cout << i << ": " << v[ i ] << endl;

  return EXIT_SUCCESS;
  }

Try entering a string of words where you press the tab key here and there.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Well, you're getting a little better. Watch your indentation.

What you need to do now is get out a piece of paper and pencil and draw yourself an array as a list of boxes big enough to write numbers in them.

Then draw yourself a box for the value of loop1. Put a 1 in the box. Write a number in the first box of the array. (It doesn't matter what number, any number will do: this is the number the user inputs.)

Now change the '1' in the loop1 box to 2, and repeat.

When you are done getting numbers from the user, (lines 11..15), you are left at line 16. Continue doing what each succeeding line does, referring to your boxes as necessary.

Good job on setting amount to zero. This works for addition and subtraction. But not multiplication. I suggest you stick to one operation at a time. Use one procedure to do addition. Another to do subtraction. Etc.

Good luck.

Duoas 1,025 Postaholic Featured Poster

OK, I've had some time now. Yes, your problem is (mostly) in convert2.

First, a syntax error you should have caught when you tried to compile this: Line 98 should read: writeln('There can''t be an operation sign at the end.'); You can't use " to delineate a string in Pascal.

For the input '1+2':
Before you started the convert2 procedure you had already read '1' and '+', so the procedure read '2' and summed 1 and 2. Then, at eoln, printed the result.

For the input '1+2+3':
Again, before starting convert2 you had alread read '1' and '+', then you read '2' and sum it, then you read '+' and quit the loop. Since '+' is not a numeric digit, you print 'error' and complain.


I think you need to throw away convert2 entirely and rethink your code. No one I know ever does this when I suggest it to them, but good programmers always do: get out a piece of paper and a pencil and draw yourself your problem. Solve it on paper. Once you know how to solve it yourself then it is much easier to tell the computer how to do it.

So, lets think about your problem quickly:

I have a line that looks like this:
1+2+3
How do I solve it myself?
I look at the first number: [B]1[/B]+2+3 I remember that as my current total.

I look at the next thing: 1[B]+[/B]2+3

Duoas 1,025 Postaholic Featured Poster

I don't want to make you feel bad, but you need to start paying a whole lot more attention.

Your CalculatorProcedure makes two errors:
1. You are using a variable when defining your array's limits. Don't do that. That should prevent your code from compiling. I've already made a very explicit note about this. (And I don't care if GPC or FP let you get away with it... That is non-standard for BP and your professor will dock you points for it.)
2. You are looping with a variable named loop1, but you are accessing the array with a variable named j --which has a random value as you never assigned it one to begin with. Likewise, amount starts with a random value, so no matter what you add to it it will still be random when you are done.

Something you are having difficulty with is indentation. Indentation helps you understand your code. Let me show you what I mean:

procedure calculatorprocedure( forloop1_1: integer );
  var
    loop1, amount: integer;
    loop1loopnumbers: array[1..100] of integer;
  begin
    { You should set amount to something useful here }

    { Since loop1 is 1, 2, 3, ..., use it to index the array... }
    for loop1:=1 to forloop1_1 do begin
      write('Write a number: ');
      readln(loop1loopnumbers[loop1]);  { ...like this }
    end;
    writeln;

    { this next statement is in the wrong place. Currently,
      it only adds one of the entered numbers to amount. }
    amount:=amount+loop1loopnumbers[loop1];

    { Good: Tell the user what the …
Duoas 1,025 Postaholic Featured Poster

You should be making better use of functions. For example, convert would be better written as:

function convert( c: char ): integer;
  begin
  convert := ord( c ) - ord( '0' )
  end;

And then used thus: digit1 := convert( c ); Also, you don't need to specify stuff after the program name. Just say: program bbb; In the whole history of Pascal specifying I/O stuff there has only once or twice actually made any difference at all (back when computers were happy with 10K of memory), and never has anyone cared either way. Since you are using a Borland dialect you can just drop it...

You should make your eqn just a little longer, like string[ 80 ] or something, just in case...

The variable currentnotblank is totally superfluous... Just test to see if c <> blank and put then and else branches as needed...

I'm sorry... I'll analyze your code better tomorrow (after I've slept some more). It is pretty scattered and you are using a lot of variables.

This is a bit of a tough assignment for a new programmer --as you know nothing about how to organize an expression reader to handle operator precedence... so you'll have to do without. However, I'll give a hint: a proper calculator expression always has the form: expression ::= number [operator expression] or, as I expect you want it: expression ::= [expression operator] number What that means is that you can expect to read an expression …

Duoas 1,025 Postaholic Featured Poster

Good enough. Bloodshed DEV is an IDE. It actually compiles your programs using either FreePascal or GNU Pascal --both of which have a Borland mode. So you'll get dynamic arrays and everything! (Bonus points! Yay!)

Duoas 1,025 Postaholic Featured Poster

Get rid of line 12. Please pay attention to the examples I've already given you. One of them answers your question (I think -about reading the letters of the first name into the string).

Pascal (as most every other language) requires constant bounds when you declare an array. For example: const MAX = 100; var a: array[ 1..MAX ] of char; Since MAX is a constant value, the compiler sees that variable definition as: var a: array[ 1..100 ] of char; You cannot use a variable in an array definition.

You are using an old Turbo Pascal, methinks? Or at least some Borland dialect? If you are you get the string data type, which, as I said, knows and reports its own length. Please see the example I already posted for you.

If you are using Delphi, you also get dynamic arrays, where you can say: var a: array of integer; You can set the length of the array: setLength( a, 100 ); As well as get the length as usual: writeln( 'The array is ', length( a ), ' integers long.' ); Hope this helps.