我对编程很陌生,所以我可能犯了很多错误helllpppp
我正在写一个用户应该输入整数的程序,那么程序应该打印出那些整数中有多少个偶数并且总和
#include <iostream>
using namespace std;
int main()
{
int n=3;
int counteven;
int count=1;
int sum=0;
cout<<"Enter the number of integers: ";
cin>>n;
while(count<=n)
cin>>n;
count++;
if (n%2==0);
{
counteven;
sum=sum+n;
cout<<"The even numbers are:"<<counteven<<endl;
cout<<"The sum of eve numbers is:"<<sum<<endl;}
system("pause");
return 0;
}
thankss
答案 0 :(得分:1)
看起来你没有任何大括号({})用于你的while循环,这可能导致它循环上线:
while(count<=n)
正确的while循环示例(取自here):
// custom countdown using while
#include <iostream>
using namespace std;
int main ()
{
int n = 10;
while (n>0) {
cout << n << ", ";
--n;
}
cout << "liftoff!\n";
}