Does that compile?

by Michael Calkins (Login MCalkins)
C-Forum

 
I can't compile it (nor the last one, actually. I experimented with the last one by deleting everything except the lines that dealt with the structure.).

For the record, I am not very experienced in C, and certainly not in C++. I'm going out on a limb even trying to answer questions in this forum.

I'm using Dev-C++/mingw.

It seems to want semicolons after each cout.

It also doesn't seem to like the for statements. I'm having trouble making sense of them also. The syntax of for in C is:

for ( expr1; expr2; expr3 ) statement;

where expr1 is usually used to initialize a counter, expr2 acts as a condition, expr3 is usually used to increment a counter, and statement is the statement to be repeated.

and it seems to be basically the same in C++

http://www.cplusplus.com/doc/tutorial/control/

So in the case of:

for (int RecCnt = 0; RecCnt {
sRec = new SalesRecord();

for (int i = 0; i {
RandNum[i] = rand();
}
sRec->Item1 = (RandNum[0] % MaxSales) + MinSales;
sRec->Item2 = (RandNum[1] % MaxSales) + MinSales;
sRec->Item3 = (RandNum[2] % MaxSales) + MinSales;
sRec->Item4 = (RandNum[3] % MaxSales) + MinSales;
sRec->Item5 = (RandNum[4] % MaxSales) + MinSales;

I'm guessing that should be more like

int RecCnt;

for (RecCnt = 0; RecCnt < 4; RecCnt++)
{
sRec = new SalesRecord();

sRec->Item1 = (rand() % MaxSales) + MinSales;
sRec->Item2 = (rand() % MaxSales) + MinSales;
sRec->Item3 = (rand() % MaxSales) + MinSales;
sRec->Item4 = (rand() % MaxSales) + MinSales;
sRec->Item5 = (rand() % MaxSales) + MinSales;
};

and that still leaves the apparent problem of not saving the pointers to the various SalesRecord structures. I'm kinda thinking sRec should be an array of pointers...

I don't know enough about C++ streams to comment on any of the file I/O.

Regards,
Michael

Posted on May 1, 2011, 5:55 AM

Respond to this message   

Return to Index

Response TitleAuthor and Date
Its all appreciatedUnseen on May 1
 Are you unchecking "Enable formatted text" when you post?Michael Calkins on May 1
  NopeUnseen on May 1
   Much better.Michael Calkins on May 1
    Thanks MC.Unseen on May 1
     You're welcome.Michael Calkins on May 2
      Well, this one outputs binaryUnseen on May 2
       Yes, it does.Michael Calkins on May 2
        Erm..Unseen on May 2
         This one seems to work :-)Michael Calkins on May 2
          You the man MC!Unseen Machine on May 2
           *ywMichael Calkins on May 2
          Here's my re-writeUnseen on May 2
           2nd Version -Unseen on May 2
            Nearly there...Unseen on May 2
             Re: Nearly there...Michael Calkins on May 2
              Thanks again MCUnseen on May 2
               arrays... (edited to fix post)Michael Calkins on May 3
                Multidimensional arrays and expandable arrays in C++ChronoKitsune on May 3
         fstream vs ifstream/ofstream (and other things about your code)ChronoKitsune on May 2
          Re: fstream vs ifstream/ofstream (and other things about your code)Michael Calkins on May 2
           (FIXED) Well, I'm not sure how well defined the behaviour is, but...ChronoKitsune on May 3
            *Thank you.Michael Calkins on May 3
    *oops. "delete SalesRecs;" should be "delete [] SalesRecs;"Michael Calkins on May 2

 Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement