我目前有这段代码:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int a;
cout << "Enter a number for a: "; //Prompts the user for a and b inputs
cin >> a;
int b;
cout << "Enter a number for b: ";
cin >> b;
cout << "A is " << a << "\tB is " << b << end1;
cout <<"Sum of a and b is equal to " << a << "+" << b << "and the result is " << (a + b) << end1;
cout <<"Product of a and b is equal to " << a << "*" << b << "and the result is " << (a * b) << end1;
cout <<"a > b is " << a << ">" << b << "and the result is " << (a > b) << end1;
cout <<"a < b is " << a << ">" << b << "and the result is " << (a < b) << end1;
cout <<"a == b is " << a << "==" << b << "and the result is " << (a == b) << end1;
cout <<"a >= b is " << a << ">=" << b << "and the result is " << (a >= b) << end1;
cout <<"a <= b is " << a << "<=" << b << "and the result is " << (a <= b) << end1;
cout <<"a != b is " << a << "!=" << b << "and the result is " << (a != b) << end1;
return 0;
}
我收到了这些错误
main.cpp: In function 'int main()':
main.cpp:10:44: error: 'end1' was not declared in this scope
我不确定我做错了什么。
最佳答案
如前所述,编辑
-
end1
->endl
(助记符:行尾) - 删除分号(分号结束语句,下一条语句将开始
<<
?) - 和将子表达式括起来(为了获得正确的优先级)
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int a;
cout << "Enter a number for a: "; //Prompts the user for a and b inputs
cin >> a;
int b;
cout << "Enter a number for b: ";
cin >> b;
cout << "A is " << a << "\tB is " << b << endl
<< "Sum of a and b is equal to " << a << "+" << b << "and the result is " << (a + b) << endl
<< "Product of a and b is equal to " << a << "*" << b << "and the result is " << (a * b) << endl
<< "a > b is " << a << ">" << b << "and the result is " << (a > b) << endl
<< "a < b is " << a << ">" << b << "and the result is " << (a < b) << endl
<< "a == b is " << a << "==" << b << "and the result is " << (a == b) << endl
<< "a >= b is " << a << ">=" << b << "and the result is " << (a >= b) << endl
<< "a <= b is " << a << "<=" << b << "and the result is " << (a <= b) << endl
<< "a != b is " << a << "!=" << b << "and the result is " << (a != b) << endl;
return 0;
}
输出:
Enter a number for a: 3
Enter a number for b: 4
A is 3 B is 4
Sum of a and b is equal to 3+4and the result is 7
Product of a and b is equal to 3*4and the result is 12
a > b is 3>4and the result is 0
a < b is 3>4and the result is 1
a == b is 3==4and the result is 0
a >= b is 3>=4and the result is 0
a <= b is 3<=4and the result is 1
a != b is 3!=4and the result is 1
关于c++ - 关于 C++ 运算符的基本问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18905859/