Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Well, you have to change the rest of your code too so that it uses 'y' and 'n' instead of yes and no.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First, get rid of that global cArray. In the class constructor allocate the required number of elements, such as aPtr = new Course[MAX]; . You will also have to create a class destructor to destroy that array with the delete[] operator.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

code tags: look in the Quick Reply box and you will see an explanation of them in the watermarks (light grey text). If you can not see them, then just put [code] at the beginning of the code and [/code] at the end, like this:

[code]

// your program goes here

[/code]

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First problem is that aPtr is declared in the class constructor. It needs to be declared in the class itself so that it can be accessed by other class methods.

What is cArray? You should probably post the class itself so that we can see what you are doing.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Edit your post and use code tags to make it easier to tell you what is wrong with it.

For starters, you do not need the two variables called yes and no. What you have to do is check for 'y' or 'n' if( yn == 'y') And remember: = is the assignment operator, == is the comparison operator. Don't confuse the two.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Like this:

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                 if( checkBox1->Checked)
                 {
MessageBox::Show( "CheckBox1 was chedked.", "Warning",
            MessageBoxButtons::OK, MessageBoxIcon::Exclamation );
                     
                 }
                 if( checkBox2->Checked)
                 {
MessageBox::Show( "CheckBox2 was chedked.", "Warning",
            MessageBoxButtons::OK, MessageBoxIcon::Exclamation );
                     
                 }
             }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>i just thought i can treat the string array as a 2d char array
You can not do that because it isn't a 2d char array.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

your program has a lot of other problems with those if statements. You can't just add digits to the strings like you are doing because there is no memory available for them. Use the += operator and remove [j] notation. Like this: arrconv[i]+='1';

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you are going to use new on line 16 then you have to delete[] it sometime later. Without that your program has a huge memory leak. Avoid that whole issue by not using pointers, declare the array on the stack. 30 strings is not going to cause stack overflow.

'g' and 'h' if statements appears twice.

A switch statement might be easier to code and read instead of all those if statements.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

We only help those who help themselves. Post the code you tried. You will have to know a little about pointers if you are required to pass variables by reference.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Learn to read MSDN articles You will have to test each checkbox to determine its state (checked or unchecked)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

never heard of such a thing, most likely because it would be grossly inefficient. The library at www.DataReel.com contains client/server code ported to both *nix and MS-Windows, but it uses standard sockets.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I began learning MFC from Microsoft's Scribble Tutorial

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Another reason not to use Turbo C for Windows programming -- it can not be use for that. Turbo C is a 16-bit compiler and can not access any of the 32-bit MS-Windows libraries or DLLs.

I didn't realize Turbo C++ Explorer is no longer available. It must not have become very popular, nothing like its predecessors Turbo C or Turbo C++.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Probably yes, see the functions in graph.h. As for ebooks, you might get some of these for Turbo C

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

In sprite.h the vertices and colours arrays can not be initialized in the class like that. It doesn't work the same as global variables. You have to put the initialization code in the class constructor.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

lines 33 and 34:
>>char *c;
>>c = &line[0];

That is not necessary. Just pass line.c_str() to the function on line 39

line 71: all you have to do is use isdigit() function if( isdigit(*c)) line 82: get rid of all that crap and use isalpha() if( isalpha(*c) ) The program is missing a set of { and }

bool primary (const char *c)
{

     if(integer(c))
        return true;
     else if (literal(c))
          return true;
     else if (*c == '(')
     {
          ++c;
          if (expr(c))
          {
             ++c;
             if (*c == ')')
             {
                ++c;
                return true;
             }
             return false;
          }
     }
     return false;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>for( int i = 0; i < argc; i++ ){
Start that loop at 1, not 0, because argv[0] is always the program name. So there is no use trying to test it.

>> if( strcmp( argv, "--lines-per-page") && i < argc ){

Two things wrong with that.
1) strcmp() returns 0 if the two strings are the same. so you need "== 0" in that statement
2) testing for i < argc is unnecessary because that is taken care of in the for statement
This is what you need: if( strcmp( argv[i], "--lines-per-page") == 0) { >>i += 2;
That is skipping too many values. just use ++i

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The loop starting on line 73 is wrong. eof() doesn't work the way you think. And you don't need that third parameter '\n' to getline() because that is the default.

while( getline(nameFile,input) )
{
   // blabla
}
nameFile.clear(); // clear error
nameFile.seekg(0, ios::beg); // back to beginning of file

After reading the end-of-file, you have to clear the stream error and set the file pointer back to the beginning of the file so that the file can be re-read. See above code snippet how to do that.

Also, move the open statement up before line 64 so that you only attempt to open the file once.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>the program adds the last number "5" twice

That's because you are wrote the loop incorrectly. Do it like this:

while ( InputStream >> n )
{
   // blabla
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

single characters take ' and ', not " and ". if( y == '1' )

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>if( argv == "--lines-per-page"
C style strings can not be compared like that. You have to call strcmp() which is in string.h if( strcmp(argv[i],"--lines-per-page") == 0) >>&& i + 1 <= argc

You need to use the < operator, not <= operator. If (i+1) == argc then your program will access outside the valid bounds of the argv array.

>>int lines = 0;
>> int columns = 0;

>>the defaults are 24 and 80, respectively

Make the default value something much more reasonable, such as 24 lines per page and 80 columns per line. You don't want to see a report that has no lines or columns because its an infinite amount of blank pages.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

In the two arguments to main(), argc is the number of arguments (command line arguments are separated by spaces or tabs), and argv is an array of the strings. So if you type this myprog --lines-per-page 30 argc will be 3 and argv will be
argv[0] = program name
argvp[1] = "--lines-per-page"
argv[2] = "30"

You don't really have to separate the strings because the C/C++ language startup code will do that for you.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You can't just simply ignore it. You have to read it and then don't use it for anything.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>void matrix_input(int mat[][dim], char* name)
What is variable name? It doesn't make much sense in the context of that function.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

use a loop that counts from 1 to the number you enter, then another loop that counts backwards back down to 1. Print the loop counter.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Because that if statement is incorrect. It uses numExs, which never changes. Its unclear what the purpose of that loop is. What is it supposed to do?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 21 is declaring a new integer and hiding the variable you declared on line 12, and that is the one the compiler is complaining about. Rewrite that line like this: for (counter = numExs; counter>0; counter--) then delete line 19.

calypso&noname commented: Very helpful and knowledgeable +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You are confusing the assignment operator = and the boolean operator ==.

line 46: use == operator, not the = operator. Similar problem in other lines of code at lines 60-69. if (leap == true) lines 32, 41,49, and 53: use = assignment operator, not == boolean operator.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Are you entering them into an integer instead of character array? Yes, then use a series of % and / operators.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

binary files are called "binary" for a reason -- they contain the computer's internal representation of the data, not something us humans can easily read. When your program reads the binary file back into the structure, then print out the values (or view them with your debugger), you should see the same thing that you saw before the structures were written out to the binary file.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You have over 200 posts and should have known the rules and that posts are not normally deleted unless they violate DaniWeb rules.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I am saying you do not need any for loops -- NONE. Just delete lines 26 thru 33 because that is the wrong way to do it. Here is all you have to do. As I said before, you are overthinking the problem, making the program too complicated.

top of loop
   enter a number
   is number < lowest
      yes, set lowest = number
   if number > highest
      yes, set highest = number
   add number to sum accumulator
   increment quantity if numbers entered
end of loop
calculate mean
infern0 commented: Great Advice +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

when is wrong is that you have too many cin's. YOu are making this a lot more difficult than it really is. All you need is one cin loop. You don't need any for loops in this program.

while( cin >> num)
{
   // do all calculations here
}
// now find the mean value and print everything.

BTW: In case you don't know, you have to press Ctrl+Z <Enter> to exit that loop.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Average: sum of all the numbers entered divided by the quantity of numbers entered. So if I enter 5 numbers (1, 2, 3, 4 and 5) the average will be (1+2+3+4+5)/5. You need to do the same thing in your program. Just keep summing them up as you enter the numbers, keeping track of how many you entered. When all done entering the numbers then you can make the final calculation.

The range is found by keeping track of the largest value entered and the smallest value entered -- you need two variables to do that. When you enter a number check to see if it is smaller than the smallest value. If yes, then change the smallest value to be the same as the number just entered. Then check if the number just entered is greater than the largest number entered so far. If yes, then change the value of the greatest number to be the value of the number just entered. When you stop entering numbers you don't have to do anything more because its all done.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I think there were server problems yesterday. A few other people had double replies also.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You would have to take the input "2 + 4" and rearrange it in reverse polish notation format. google for it and you will find examples.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yes, it will compile both C and C++ programs. Just name the file with *.c extension and it will be compiled as a C program.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Implement them as function pointers.

kvprajapati commented: Well said. +6
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I think you have to rearrange this into polish notation. For example, if I enter "100 + 2" when the + operator is reached your program attempts to pop two values off the stack, then in fact there is only one value (100).

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

CString class is actually not belong the MFC class library. It is in ATL. You can use appropriate ATL headers to use CString in any Windows C++ application.
For more information on how you can use CString in a C++ project, read thease articles.
string classes

How to use CString

I think Microsoft has changed CString since VC++ 6.0, where it was part of MFC. In VC++ 2005 and later compilers you reminded me that they changed it to be part of ATL, as they did many other MFC classes.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

...in the above blurb of code (post #3 in this thread), if <string> is replaced with <string.h>, the whole thing flies apart! If its not asking too much, I'd love an explanation of that one.

<string.h> is from C language and contains prototypes for C's standard string handling functions for character arrays, such as strcmp(), strcpy(), etc. It can be used in either C or C++ programs. When used in c++ programs <string.h> is normally renamed <cstring>. The only difference between the two is that <cstring> puts all those functions in std namespace while <string.h> the functions are in global namespace.

<string> is c++ only and contains the standard STL (standard template library) string class. It's completly independent of anything that is in string.h. Both <string> and <cstring> can be used in the same c++ program.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

One problem with your program is that the value of MAX may or may not be big enough. If I enter the value 10 then MAX is too large because 10 in binary is only 4 digits (1010). But if I enter the value of 123456 the binary value is 11110001001000000, which is clearly larger than 8 digits.

Instead of using an array of ints to hold the 1's and 0's just put them in a large character array, then keep track of the number of digits actually used in an integer.

So the calculation in the first loop you posted stops when the value of num is 0.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Every program must have one main() function. The code you posted does not have that.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Next time use code tags when posting code. That [code] link isn't just to make DaniWeb pretty.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you have to use pointers to pointers (double stars)

const int dataSize1 = 5;
const int dataSize2 = 6;

void LoadData(char** file, float** data1, float** data2)
{
       // read data size and contents from file
       *file = new char[255];
       strcpy(*file, "This is a test");
      *data1 = new float[dataSize1];
      *data2 = new float[dataSize2];
      // store data
      (*data1)[0] = 1.0f;
      (*data2)[0] = 2.0f;
      // etc ...
}
int main()
{
    char *f1 = 0;
    float *f2 = 0, *f3 = 0;
    LoadData(&f1, &f2, &f3);
    cout << f1 << " " << f2[0] << " " << f3[0] << "\n";
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you need to use code tags.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The console is a shared resource among all threads. It would be just a jumbled mess if one thread tried to output text to the console screen at the same time you are trying to input text with fgets(). I would think you need to redesign the threads so that confusion doesn't happen.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you might want to call the >> operator in the while loop instead of get_account_number() so that the program can get the input data

while( cin >> b )
{
     if( b.get_account_number() == -1)
     {
              break;
     }
     // blabla

}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you naming of the file is confusing. infile is usually referencing a istream object. ostream objects are normally named outfile.

line 26: all that does is return the account number. There is nothing in that loop that will change the account number, thus its an infinite loop. line 38 calls the overloaded << operator, and it doesn't change the value of b either. So I have no idea from what you have posted how the values in b ever get changed. I assume the program should be calling the >> operator with an ifstream object somewhere. But that's never called in your program either.