저는 코딩 초보자인데이 코드를 고칠 수 없어 미쳐 가고 있습니다. 특정 변수가 선언되지 않았으며 수정 방법을 잘 모르겠습니다.
#include <iostream>
using namespace std;
int main()
{
int (a = 0), sum;{
cout << "This program should read all integer numbers ";
cout << "to sum until a negative number is entered\n";
exit(0);
}
while(a < 0) {
cout << "Enter an integer number: ";
cin >> a;
sum += a;
}
cout << "The sum is sum\n";
return 0;
}
sum을 초기화하지 않았으므로 어떤 값으로도 시작할 수 있습니다.
{ }
아무 이유없이 주변 에 무의미한 층이 추가로 있습니다 .
최종 cout
진술은 실제로 변수를 인쇄하지 않습니다.
다음으로 변경하십시오.cout << "The sum is " << sum << "\n";
#include <iostream>
using namespace std;
int main()
{
int a = 0, sum = 0;
cout << "This program should read all integer numbers ";
cout << "to sum until a negative number is entered\n";
do {
cout << "Enter an integer number: ";
cin >> a;
if (a > 0)
{
sum += a;
cout << "The sum is currently: " << sum << "; but this is not yet the final value.\n";
}
} while(a > 0) ;
cout << "The sum is " << sum << "\n";
return 0;
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다