0
Im相當新的節目,所以我大概賺了不少錯誤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
好斑點,我真的抓我的頭在那一個!奇怪地將一個char傳入cin導致循環中斷。我通常是一個PHP程序員,所以這可能是一個簡單的解釋! –
它看起來像程序期望n是一個整數,並且如果n是char,許多使用的操作(n%2 = 0或count <= n)將會中斷或無法正常運行。 – Umibozu
ohh thanks alott我還必須初始化counteven,但程序不工作:(這個代碼中有什麼錯誤嗎?真的很感謝幫助! – jammah