سؤال

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.

هل كانت مفيدة؟

المحلول

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 ".

نصائح أخرى

'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.

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top