我正在尝试使用GradePoint()函数来创建GPA计算器来进行实际转换,将int main()用于cin和cout .
我被困了几个小时 . 我尝试了许多不同的东西,并查找了许多不同的教程,但似乎没有什么似乎与我需要做的相似 .
GradePoint() function requirements are as follows.
此功能将导致两种结果之一 . 如果参数介于0和100之间,则该函数会将等级四舍五入为最接近的整数并返回等效的GPA值 . 否则,如果进入的等级不在0和100之间,则该函数将抛出std :: out_of_range异常 .
int main() requirements are as follows.
提示用户输入成绩并确保其为数字 . 不要验证范围,因为这将在GradePoint()函数中完成 .
#include
#include
using namespace std;
//function prototypes
double GradePoint(double p);
// testing some funtions
int main()
{
double p = 0.0;
cout << "Please a percentage grade to convert to grade points: ";
cin >> p;
while(!(cin >> p))
{
cin.clear();
cin.sync();
cout << "Please enter a numeric value: ";
}
cout << "A percentage grade of " << p;
cout << " Is a grade point average of " << GradePoint;
return 0;
}
double GradePoint(double p)
{
double g;
if (p >=90 && p <=100)
g = 5.0;
else if (p >=85 && p <=89)
g = 4.5;
else if (p >=80 && p <=84)
g = 4.0;
else if (p >=75 && p <=79)
g = 3.5;
else if(p >=70 && p <=74)
g = 3.0;
else if (p >=65 && p <=69)
g = 2.5;
else if (p >=60 && p <=64)
g = 2.0;
else if (p >=55 && p <=59)
g = 1.5;
else if (p >=50 && p <=54)
g = 1.0;
else if (p <50)
g = 0.0;
return g;
}