gpt4 book ai didi

c++ - cout 中的意外输出

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:44:02 28 4
gpt4 key购买 nike

<分区>

所以,这是我在 Stack Overflow 上的第一个问题。在经历了一些 MATLAB 的艰苦奋斗之后,我正在学习 C++。我有一个简单的练习,构建良好,但没有产生预期的结果。

我也没有收到任何错误。我正在运行 Xcode 5。

我怀疑问题与变量的初始化有关。当我查看调试时,我的变量保持设置为 0。

#include <iostream>
using namespace std;

int main()
{

//Declare variables
int score = 0;

//input score
cout << "Emter score: ";
cin >> score;


if (score == 100)
{
cout << "Final Score: " << score;
cout << "You received a perfect score! \n";
// 100% is an A.
}
else if ((score >= 90) && (score <= 100))
{
cout << "Final Score: " << score;
cout << "Your grade is an A. Nice Job! \n";
// 90-100 is an A.
}
else if ((score >= 80) && (score <= 89))
{
cout << "Final Score: " << score;
cout << "Your grade is a B. Well done. \n";
// 80-89 is a B.
}
else if ((score >= 70) && (score <= 79))
{
cout << "Final Score: " << score;
cout << "Your grade is a C. Really? \n";
// 70-79 is a C.
}
else if ((score >= 60) && (score <= 69))
{
cout << "Final Score: " <<score;
cout << "Your grade is a D. You suck. Seriously. \n";
// 60-69 is a D.
}
else if ((score >= 0) && (score <= 59))
{
cout << "Final Score: " << score;
cout << "You got an F! YOU FAIL! GO JUMP OUT THE WINDOW. \n";
// 0-59 is an F.
}

return 0;
}

抱歉发了这么长的帖子,我不想遗漏任何东西。再次感谢。

ETA:修复了换行符。我一行一行地重新输入代码,它运行得很好。我怀疑这与所有这些内容的转换方式有关,但我不确定。

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com