- 论坛徽章:
- 0
|
不好意思,问一个菜鸟问题,关于c++
这个其实我也知道,不过有一个程序,要找错误,有一个错误就在*/上面,有点糊涂了,我贴上来大家帮我看看吧。
#include <iostream>;
using namespace std;
// function prototypes
float combinedMark( float labs, float midterm, float assignment, float final );
float adjustMark( float rawTotal, float final, char failFinalFailCourse );
// main() - get input marks, and find out whether or not the instructor
// decides to enforce the "need to pass the final exam to pass the course"
// rule. Then compute (and print) the final grade. If a student fails the
// final exam, but his/her combined average is 50% or more, then a mark of
// 49% will be printed.
int main( void )
{
char failFinalFailCourse;
float labs;
float midterm;
float assignment;
float final;
float total;
float finalGrade;
int integerGrade;
// read the various marks from the keyboard
cout << "Enter your total lab mark (/ 200): ";
cin >;>; labs;
cout << "Enter your midterm mark (/ 90): ";
cin >;>; midterm;
cout << "Enter your assignment mark (/ 60): ";
cin >;>; assignment;
cout << "Enter your final exam mark (/ 120): ";
cin >;>; final;
// ask if the "fail final, fail course" rule is in effect
cout << "Will you fail the course if you failed the final exam?\n";
cout << "Enter Y or N: ";
cin >;>; failFinalFailCourse;
// compute the combined mark and the final mark
total = combinedMark( labs, midterm, assignment, final );
finalGrade = adjustMark( total, final, failFinalFailCourse );
// display the final mark as an integer
integerGrade = finalGrade + 0.5; // round off
cout << "Your final grade for the course is "
<< integerGrade << "%.\n";
return 0;
}
// combinedMark - function to combine the labs marks (out of 200), midterm
// marks (out of 90), assignments (out of 60), and final exam mark (out of 120)
// to obtain a final mark for the course. The weight of each is:
// labs: 15%
// midterm: 25%
// assignment: 15%
// final: 45%
float combinedMark( float labs, float midterm, float assignment, float final )
{
// Pre: labs, midterm, and final are all >;= 0
// Post: return the tentative final mark for the course
float scaledLabs;
float scaledMidterm;
float scaledAssignment;
float scaledFinal;
float combined;
scaledLabs = labs * 15 / 200;
scaledMidterm = 25 / 90 * midterm;
scaledAssignment = assignment * 15 / 60;
combined = scaledLabs + scaledMidterm + scaledAssignment * scaledFinal;
return combined;
}
// Adjust marks so that if one fails the final exam and the "fail the
// final, fail the course" rule is in effect, then a final grade of 49%
// is assigned.
float adjustMark( float rawTotal, float final, char failFinalFailCourse )
{
// Pre: rawTotal and final are >;= 0, and
// failFinalFailCourse is either 'Y' or 'N'
// Post: return the student's assigned course grade
if( failFinalFailCourse = 'Y' && final < 60 || rawTotal >;= 50 )
return 49;
return rawTotal;
}
里边有5个错误,有一个是25/90*midterm的,如果按照这个,每次计算midterm都是0。 |
|