just one problem

my program is about high school dance cost report

its project 07 1 of 2 projects left in the class and im almost done with im only having one problem

i been trying to fix this problem for a few hours with function, and anything that could help me.

my class is an intro to c++


i made some images

i did a page break
the problem is at the top where current name is display

the first page doesn't display the current name the second one does

Attachments Proj07-image_01.jpg 29.16 KB Proj07-image_02.jpg 34.64 KB

It's hard to help you with your code if you don't show the code!

Are both these displays generated by the same function? Are you sure you're passing a name to the function in the first instance?

Have you tried stepping through the program with a debugger to see why a name isn't passed/displayed?

here is my code

int main()
{

// open file

openFile();





// if file fails to open
if (inFile.is_open())
  {   


      PrintHeader();
    while (! inFile.eof() )
    {
    process();
   }
    finishUp();
inFile.close();
  }
  else cout << "Unable to open file"; 

  return 0;
}
/* Open File */
void openFile(void)
{
    inFile.open("HBdance.fil");
    return;
}
void process(void)
{
    file();
    performCalc();
    PageBreak();
    displayReport();
    getline(inFile, line);
    tRec++;


return;
}
/* Calculations */
void file(void)
{
    inFile >>sFname>>sLname>>fcloth>>ftrans>>fFlowers>>fdinner>>ftickets>>magQty>>canQty;
        strcpy_s(sStName,sFname);
        strcat_s(sStName," ");
        strcat_s(sStName,sLname);
return;
}
void performCalc(void)
{

    cDrive();
    mDrive();
    Calc();

return;
}


/* Display Reports */
void displayReport(void)
{





iLineCount = iLineCount + 2; 


    grandTotCost = grandTotCost + totCost;
    schTotCost = schTotCost + scCost;
    parTotCost = parTotCost + pCost;
    stuTotCost = stuTotCost + stCost;

    cout<<fixed<<setprecision(2)<<endl;
    cout<<setw(9)
        <<sFname
        <<setw(9)
        <<sLname
        <<setw(13)
        <<pCost
        <<setw(15)
        <<stCost
        <<setw(13)
        <<scCost
        <<setw(15)
        <<totCost
        <<endl;




return;
}
/* Grand Totals */
void gTotals(void)
{



    cout<<fixed<<setprecision(2)<<endl;
    cout<<"\nGrand Totals            :"
        <<""
        <<parTotCost
        <<"        "
        <<stuTotCost
        <<"       "
        <<schTotCost
        <<"        "
        <<grandTotCost
        <<endl;



return;
}
void tRecords(void)
{


cout<<"Total Records:  "<<tRec++ <<endl;





return;
}
void PageBreak(void)
{


    if (iLineCount >= 12)
    {
 system("pause");
  PrintHeader();

    }


    return;

}

void PrintHeader(void)
{




   iLineCount = 0;   //reset line counter to 0

   system("cls");
    cout<<"\n                          High School Dance                               ";
    cout<<"\nCurrent Name: "<<sStName;
    cout<<"\n\n     Name           "<<"Parents Cost   "<<"Student Cost   "<<"School Cost   "<<"Total Cost   "<<endl;




return;
}
void finishUp(void)
{

    gTotals();
    tRecords();


    return;
}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

You call PrintHeader() before calling process(), so sStName is empty on first call of PrintHeader()

...and please use code tags!!!

It also is apparent you are using a LOT of global variables. This is generally a poor practice. Had you been using local variables (most of which would be declared in main() ) you would have been able to see your problem sooner.

Go back to your text and notes on constructing functions - use the parameter list to limit what data a function can see and affect.

This article has been dead for over six months. Start a new discussion instead.