我用float函数很难用返回值。每次我尝试输入一个返回值时,我都会收到错误的未知值,或者您必须输入一个返回值。我很迷茫。带浮点函数的C++错误4716
这里是我的程序:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
string studFirstName;
string studLastName;
float studExam1;
float studExam2;
float studExam3;
float studScore;
float studAvg;
void getStudName(string& studFirstName, string& studLastName);
void getStudExams(float& studExam1, float& studExam2, float& studExam3);
float calStudAvg(float studExam1, float studExam2, float studExam3);
void displayGrade(string studFirstName, string studLastName, float studavg);
int main()
{
cout << "Enter Student's First Name:";
cin >> studFirstName;
cout << endl;
cout << "Enter Student's Last Name:";
cin >> studLastName;
cout << endl;
}
void getStudExams(float& studExam1, float& studExam2, float& studExam3)
{
cout << "Enter score for Exam 1:";
cin >> studExam1;
cout << endl;
cout << "Enter score for Exam 2:";
cin >> studExam2;
cout << endl;
cout << "Enter score for Exam 3:";
cin >> studExam3;
cout << endl;
}
float calStudAvg(float studExam1, float studExam2, float studExam3)
{
float studScore = (studExam1 + studExam2 + studExam3);
float studAvg = (studScore/3);
return;
}
void displayGrade(string studFirstName, string studLastName, float studAvg)
{
cout << "Student's First Name:";
getline (cin, studFirstName);
cout << endl;
cout << "Student's Last Name:";
getline (cin, studLastName);
cout << endl;
cout << left << "Student's Final Grade:"
<< right << studAvg << endl;
if (studAvg >= 90)
cout << "Grade = 'A'" << endl;
else if (studAvg >= 80)
cout << "Grade = 'B'" << endl;
else if (studAvg >= 70)
cout << "Grade = 'C'" << endl;
else if (studAvg >= 60)
cout << "Grade = 'D'" << endl;
else
cout << "Grade = 'F'" << endl;
system("pause");
}
,如果任何人有任何想法,我真的需要帮助!谢谢
return; ???你要么返回studScore或studAvg。 – Jagannath 2014-11-04 05:38:43
我试了两次,它给了我一个致命的错误。 – 2014-11-04 05:40:44
您抱怨编译错误。这解决了编译错误。您尚未显示您是如何调用该方法的。 – Jagannath 2014-11-04 05:45:28