2

私は現在、このコードを持っています:

#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

何が間違っているのかわかりません。

4

7 に答える 7

7

前述のように、編集

  • end1-> endl(ニーモニック: 行末)
  • セミコロンを削除します (セミコロンはステートメントを終了し、次のステートメントは? で始まり<<ます)
  • サブ式を括弧で囲みます(優先順位を正しくするため)

Coliruでライブを見る

#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
于 2013-09-19T22:27:30.660 に答える
5

end1そうしないとendl、このエラーが発生します。

end1エラーは、スコープ内に見つからないなど、コンパイラが何がわからないかを説明しています。これは単に のスペルミスでありendl、実際にはスコープ内に存在します。

coutさらに、各行の前にセミコロンが必要であるか、最終出力までセミコロンがありません。

于 2013-09-19T22:21:22.450 に答える
2

最初のエラーは、endl<---lowercase L の代わりに end1<---number 1 を使用したためです。

残りのエラーは、その行をセミコロンで終了したためです。出力を 1 つの長い式として続けたい場合は、最後にセミコロンを使用しないでください。おそらく、代わりにこれらの各行の先頭で cout を使用する方が読みやすいでしょう。このような:

cout << "A は " << a << "\tB は " << b << endl; cout <<"a と b の合計は " << a << "+" << b << " に等しく、結果は " << a + b << endl; cout <<"a と b の積は " << a << "*" << b << " に等しく、結果は " << a * b << endl;

于 2013-09-19T22:26:52.750 に答える
1

それは解決策です....

#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;
   cout <<"Sum of a and b is equal to " << a << "+" << b << "and the   result is " << (a + b) << endl;
   cout <<"Product of a and b is equal to " << a << "*" << b << "and  the result is " << (a * b) << endl;
   cout <<"a > b is " << a << ">" << b << "and the result is " << (a > b) <<  endl;
   cout <<"a < b is " << a << ">" << b << "and the result is " << (a < b) << endl;
   cout <<"a == b is " << a << "==" << b << "and the result is " << (a == b) << endl;
   cout <<"a >= b is " << a << ">=" << b << "and the result is " << (a >= b) << endl;
   cout <<"a <= b is " << a << "<=" << b << "and the result is " << (a <= b) << endl;
   cout <<"a != b is " << a << "!=" << b << "and the result is " << (a != b) << endl;

   return 0;
}
于 2016-07-17T06:22:12.273 に答える
1
#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;
   cout <<"Sum of a and b is equal to " << a << "+" << b << "and the   result is " << (a + b) << endl;
   cout <<"Product of a and b is equal to " << a << "*" << b << "and  the result is " << (a * b) << endl;
   cout <<"a > b is " << a << ">" << b << "and the result is " << (a > b) <<  endl;
   cout <<"a < b is " << a << ">" << b << "and the result is " << (a < b) << endl;
   cout <<"a == b is " << a << "==" << b << "and the result is " << (a == b) << endl;
   cout <<"a >= b is " << a << ">=" << b << "and the result is " << (a >= b) << endl;
   cout <<"a <= b is " << a << "<=" << b << "and the result is " << (a <= b) << endl;
   cout <<"a != b is " << a << "!=" << b << "and the result is " << (a != b) << endl;

   return 0;
}

新しい行を表すために「end1」と書きました.bt正しいキーワードは「endl」(行の終わり)です.解決策は上記です...

于 2015-11-27T21:06:45.950 に答える
-1

まず第一に、そうであり、そうではendlありませんend1(最後の文字は1ではなくLです)

cout次に、演算子で始まるすべての行の前に置く必要があります<<。それはうまくいくでしょう。

于 2013-09-19T22:23:13.597 に答える