我目前有这个代码:
#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;
}
Run Code Online (Sandbox Code Playgroud)
我收到这些错误
main.cpp: In function 'int main()':
main.cpp:10:44: error: 'end1' was not declared in this scope
Run Code Online (Sandbox Code Playgroud)
我不确定我做错了什么.
如上所述,编辑
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;
}
Run Code Online (Sandbox Code Playgroud)
输出:
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
Run Code Online (Sandbox Code Playgroud)
end1endl否则应该发生此错误.
该错误解释了编译器如何不知道什么end1是,例如在范围中找不到.它只是一个拼写错误endl,实际上确实存在于范围内.
此外,您需要cout在每行前面或不要有分号,直到最终输出.