我用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