错误:ld在2015年6月返回1退出状态

时间:2015-06-22 00:17:39

标签: c++ compiler-errors linker-errors

我需要帮助理解[Error] id return 1 exit status due to 2 undefined references: getGrades() and getAverage()。我被发布了 DEV C ++ 并且轻轻地挫败了语法错误,但这些“链接”错误仍然给我带来了困难。这是代码的最新更新,如果有人可以帮助我理解这些很好的链接错误。 编译器 - 开发C ++ Windows 7的 代码:

#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
using namespace std;

// Function declarations
string getStudentName();
string getWork();
int getGrades();
double getAverage();


int main()
{
    string studentName, work[3];
    int grades[3];

    double average;

    // Get the name of the student
    studentName = getStudentName();

    // Get the work
    work[3] = getWork();

    // Get the grades
    grades[3] = getGrades();

    // Get the average
    average = getAverage();

    // Dynamic spacing for grades
    ostringstream ss;
    int gradesLength = ss.str().length();
    ss <<setprecision(0) << fixed << showpoint;
    ss << grades;
    cout << "\n the average for " << studentName << " is: " << average << endl;
    cout << "The grades for " << studentName << " are: " << endl;
    cout << setw(30) << work[0] << ": " << setw(gradesLength) << grades[0] << endl;
    cout << setw(30) << work[1] << ": " << setw(gradesLength) << grades[1] << endl;
    cout << setw(30) << work[2] << ": " << setw(gradesLength) << grades[2] << "\n\n\n";
    cout << "You have completed the program: \n";
    return 0;
}

// Student Name
string getStudentName()
{
    string name;
    cout << "Enter students full name: ";
    getline(cin, name);
    return name;
}

// Assignments
string getWork()
{
    string work[3];
    cout << "\nEnter the name of each assignment \n";
    cout << "First assignment: ";
    getline (cin, work[0]);
    cout << "Second assignment: ";
    getline (cin, work[1]);
    cout << "Third assignment: ";
    getline (cin, work[2]);
    return work[3];
}

// Grades
int getGrades(string work[3])
{
    int grades[3];
    cout << "\nEnter the grade for " << work[0] << ": ";
    cin >> grades[0];

    cout << "Enter the grade for " << work[1] << ": ";
    cin >> grades[1];

    cout << "Enter the grade for " << work[2] << ": ";
    cin >> grades[2];
    return grades[3];
}

// Math
double getAverage(int grades[3])
{
    double average;
    average = (grades[0] + grades[1] + grades[2]) / 3.0f;
    return average;
}

0 个答案:

没有答案