2
#include <iostream>
int main()
{
int cnt = 0, sum = 0, value = 0;
std::cout << "Please enter a set of numbers and then press ctrl+z and ENTER to add the numbers that you entered" << std::endl;
if (cnt = value)
++cnt;
while (std::cin >> value)
sum += value;
std::cout << "the sum is: " << sum << std::endl;
std::cout << "the amount of numbers you entered are: " << cnt << std::endl;
return 0;
}
私が持っているifステートメントは間違っていて、ユーザーが入力する整数の数は数えません。ループを使用してユーザーが入力する整数をカウントします。
ループを使用して入力する整数の数をプログラムでカウントするにはどうすればよいですか?新しい入力が与えられるたびに
あなたは、入力と出力の例 –
を提供する必要がある[ツアー]をお読みください。あなたのタイトルは、単語ではなく関連性のない情報から始まります。あなたの質問に対する答えはYesです。 (これはひどく尋ねられる質問になります)。 – Anthon
ところで、警告を有効にする必要があります。あなたのコンパイラはおそらく 'if(cnt = value)'について警告するでしょう。https://stackoverflow.com/questions/17681535/variable-assignment-in-if-condition – stephan