尝试编译文件时出现非常奇怪的错误

时间:2011-11-21 21:55:36

标签: c++

错误:

Error when trying to compile

链接,因为您无法在嵌入时使图像变大:http://i.imgur.com/IWJyT.png

我不知道问题是什么。我之前从未见过格式化,所以我发布了一个屏幕截图。

包括整个代码,因为我不知道错误是什么。我没有别的东西可以添加到这个问题,但系统认为我这样做。我还能添加什么?

#include <iostream>     //Basic input/output
#include <iomanip>      //Manipulators
#include <string>       //String stuff 
#include <fstream>

using namespace std;

void instruct ();       //Function declaration for printing instructionstring studname ();
void input (ifstream &infile, float& test1, float& test2, float& test3, float& test4, float& test5, float& test6, float& test7, float& test8, float& test9, float& test10, string& studentname);      //Function declaration for input
float aver (float test1, float test2, float test3, float test4, float test5, float test6, float test7, float test8, float test9, float test10);      //Function declaration for calculating average
void output (string studentname, float average);      //Function declaration for output



int main()
{
  float test1 = 0;              //Vars (test1 - test10) for test scores
  float test2 = 0;
  float test3 = 0;
  float test4 = 0;
  float test5 = 0;
  float test6 = 0;
  float test7 = 0;
  float test8 = 0;
  float test9 = 0;
  float test10 = 0;
  string studentname = "a";     //Define Var for storing students name
  float average = 0;            //Define var for storing average


  instruct();     //Function call to print instructions


  ifstream infile("grades.dat");

  input (infile, test1, test2, test3, test4, test5, test6, test7, test8, test9, test10, studentname);     //Function call for scores

  while (!infile.eof())
    {
      average = aver (test1, test2, test3, test4, test5, test6, test7, test8, test9, test10);    //Function call for average

      output (studentname, average);     //Function call for output

      cin.ignore(1);

      input (infile, test1, test2, test3, test4, test5, test6, test7, test8, test9, test10, studentname); //Get new input
    }     //end eof

  return 0;
}

/***************************************************/
/* Name: instruct                                  */
/* Description: Print instructions to user.        */
/* Paramerters: N/A                                */
/* Return Value: N/A                               */
/***************************************************/

void instruct()
{
  cout << "\n" << "This program will calculate the average of 10 test scores that you input. " << "\n" << "\n";
  //Prints instructions

  return;
}

/***************************************************/
/* Name: input                                     */
/* Description: Get input                          */
/* Paramerters: N/A                                */
/* Return Value: N/A                               */
/***************************************************/

void input (float& test1, float& test2, float& test3, float& test4, float& test5, float& test6, float& test7, float& test8, float& test9, float& test10, string& studentname, ifstream& infile)

{
  infile >> studentname;
  infile >> test1 >> test2 >> test3 >> test4 >> test5 >> test6 >> test7 >> test8 >> test9 >> test10;
  infile.ignore(10, '\n');

  return;
}



/***************************************************/
/* Name: aver                                      */
/* Description: Calculate Average                  */
/* Paramerters: N/A                                */
/* Return Value: aver                              */
/***************************************************/


float aver (float test1, float test2, float test3, float test4, float test5, float test6, float test7, float test8, float test9, float test10)

{
  float aver = 0;
  aver = test1 + test2 + test3 + test4 + test5 + test6 + test7 + test8 + test9 + test10;
  aver = aver / 10;
  return aver;
}


/***************************************************/
/* Name: output                                    */
/* Description: Calculate Average                  */
/* Paramerters: N/A                                */
/* Return Value: aver                              */
/***************************************************/

void output (string studentname, float average)      //Function declaration for output
{ 

  cout << studentname;

  cout << average;

  return;
}

正在阅读文件:

Number One
99 99 99 99 99 99 99 99 99 99
John Doe
90 99 98 89 87 90.2 87 99 89.3 91
Clark Bar
67 77 65 65.5 66 72 78 62 61 66
Scooby Doo
78 80 77 78 73 74 75 75 76.2 69
Santa Clause
89 92.5 94 95 91 89 88 90 92 91
Jessie James
45 54 55 56 66 61 65.6 67 43 54
Clara Barton
87 88 76 75.7 80 88 83 84 85 81.2
Alex Mack
55 65 66.5 67 76 77.7 66 67.8 71 70
Ann Apolis
87 88 88 88 88 85.4 81 82 89 81
Stewart Mouse
90 92 93 94 95 96 97 97.7 98 99
Sue Sloan
88.5 67.7 88.8 99.9 90.9 89 87 78 89 88
Luke Skywalker
76.7 77.8 88.8 76.7 77 88 87 86 85 80.9
Harry Potter
80 83 84 85 86 79.4 78.5 81 80 82
Mary Poppins
100 100 100 100 100 100 100 100 100 100
Last One
33 44 55 66 77 88 99 22 11 91

3 个答案:

答案 0 :(得分:6)

输入功能的参数列表不匹配。您已经更改了最高版本和最低版本之间的顺序。

最底层的应该是:

void input ( ifstream& infile, float& test1, float& test2, float& test3, float& test4, float& test5, float& test6, float& test7, float& test8, float& test9, float& test10, string& studentname)

答案 1 :(得分:2)

您声明了一个函数input(ifstream &, float &, ...),但之后从未定义它,当然,编译器找不到它。也许函数input(float&, ...)意味着失踪的那个?

顺便说一下,使用矢量或类似的东西传递数据会更优雅。这将使代码更加通用(截至目前它仅适用于读取10个数字)。

答案 2 :(得分:1)

编译器错误undefined symbol表示您已经声明了某些内容,并尝试在代码中的某处使用它,但您尚未对其进行定义。

鉴于这是家庭作业,我不打算给你答案,但让你努力工作。我会给你一个暗示。该错误消息抱怨名为input的函数。有一个名为input的声明,我看到还有一个名为input的定义。它们是一样的吗?仔细看看。