-1

I have the following code

#include "stdafx.h"
#include <iostream> 
using namespace std;
#include "graderec.h"

int main( )
{
    GradeRecord studentAnn("45-2791", 14, 49);
    GradeRecord studentBob("67-5803",25, 50);

    int bobsUnits;
    int bobsGradePoints;
    int annsUnits = 4;
    int annsGradePoints = 16;

    cout << "Ann's Grade Information:" << endl;
    studentAnn.writeGradeInfo();

    cout << endl;

    cout << "Bob's Grade Information:" << endl;
    studentBob.writeGradeInfo();

    cout << endl;

    cout << "Enter Bob's units: ";
    cin >> bobsUnits;

    cout << "Enter Bob's grade points: ";
    cin >> bobsGradePoints;

    cout << endl;

    cout << "Bob's Grade Information:" << endl;
    studentBob.updateGradeInfo(bobsUnits, bobsGradePoints);
    studentBob.writeGradeInfo();

    cout << endl;

    cout << "Ann's Grade Information:" << endl;
    studentAnn.updateGradeInfo(annsUnits, annsGradePoints);
    studentAnn.writeGradeInfo();

    system("PAUSE");
    return 0;

}

void asterisks()
{ 
    cout << "************************************************************************" << endl;

} 

I need to use a free function to display about 60 asterisks where I have cout << endl. I followed the example that I was giving but can't get it to work.

The code below is the example that I was given on how a free function looks.

void companyBanner()
{
  cout << *************************** << endl;
  cout << **     Tech Guys LLC     ** << endl;
  cout << *************************** << endl; 
  cout << endl;
}

Updatea: Got it working, thanks for the help everyone. I rewrote the free function and added asterisks() above the main again and it worked. Must have been something in the free function that was causing it to not work.

Jacob
  • 21
  • 1
  • 6
  • You're almost there, simply call `asterisks();` where you want to. For basic stuff such as this, you should probably grab a [good C++ book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – Angew is no longer proud of SO Jun 25 '13 at 13:10
  • Your example is missing quotes around the strings. – James M Jun 25 '13 at 13:10
  • Put your string in a double quotation. `cout << "******" << endl;` – frogatto Jun 25 '13 at 13:12
  • You do not define the prototype of the function `asterisk()`. Put a `void asterisk();` above the `int main()` – frogatto Jun 25 '13 at 13:18
  • @Angew I would buy a good C++ book but don't have the means for it right now cause I had to buy a outdated c++ book that was over $300. – Jacob Jun 25 '13 at 13:28

3 Answers3

0

You should call the function you defined otherwise it will never be executed.

You should also place either a declaration or the whole definition of the function before you call it for the first time.

String literals should be enclosed in double quotes ".

Ivaylo Strandjev
  • 69,226
  • 18
  • 123
  • 176
0

'Doesn't work' is too vague for us to help you. My attempt for now is that you have not prototyped your asterisks() function. Put void asterisks(); above your main.

MadPidgeon
  • 225
  • 1
  • 7
0

If I understand the question (please tell me if I'm wrong), just replace cout << endl; by a call to your function: asterisks().

Also, either move the function asterisks before your main, or add the prototype void asterisks(); above the main.

Maxime Chéramy
  • 17,761
  • 8
  • 54
  • 75