C++ 输出错误
我已经纠正了下面程序中的错误,但仍然得到混合输出。最新结果如下。请告知 我将感谢任何帮助。有关的守则部分包括:C++ 输出错误,c++,visual-c++,syntax,C++,Visual C++,Syntax,我已经纠正了下面程序中的错误,但仍然得到混合输出。最新结果如下。请告知 我将感谢任何帮助。有关的守则部分包括: string student::standing() const // post: use selection to return the current standing as either // Freshman, Sophomore, Junior, or Senior. { cout
string student::standing() const
// post: use selection to return the current standing as either
// Freshman, Sophomore, Junior, or Senior.
{
cout << "Freshman";
if (my_credits <= 60.00);
{cout << "Sophomore";}
if (my_credits <= 90.00);
{cout << "Junior";}
if (my_credits >= 90.00);
else
{ cout << "Senior";}
}
string student::name() const
// post: return the student's name
{
{return my_name;}
}
string student::standing()常量
//post:使用所选内容将当前站立状态返回为
//大一、大二、大三或大四。
{
嗯,首先,你的标题引用了一个错误,而你的问题显示了另一个错误。这两个都是合法的,所以让我们来解决这两个问题,好吗
问题是C4716错误消息准确地告诉您错误是什么:您只需要读取它。它说函数student::standing()
声明返回字符串,但没有。当然,这不是唯一的问题。另一个问题,您声明是C2134(但可能是C4390)是因为您在if
后面加了一个分号,这不正确。此代码:
if(my_credits <= 60.00);
{cout << "Sophomore";}
作为将来的参考,如果你在谷歌上搜索C4390,你会在上面登陆,其中包括对问题的准确描述,以及你所犯的错误
类似地,如果你在谷歌上搜索C4716,你可能会在上面找到一个与你的错误非常接近的例子
最后,在此代码中:
if(my_credits <= 60.00)
/* do nothing if my_credits are less than or equal to 60 */
{
/* and then always print "Sophomore" */
cout << "Sophomore";
}
string student::name() const
{
{return my_name;}
}
这些额外的卷发背带有什么意义?它们并没有伤害任何东西,但它们只是起不到任何可以想象的作用,只是为了混淆。移除它们:
string student::name() const
{
return my_name;
}
@Nik Bougalis谢谢你的帮助。我的教授也没听懂;不客气。你的程序现在有效吗?有效。我已经学习这两周了,我迫不及待地想变得更熟练。@Nik Bougalis。如果你有问题,请陈述。如果新问题与原问题不同,请接受新问题正确回答原问题,并分别发布新问题。
string student::name() const
{
return my_name;
}