-2
Holle、私のC++ PrimerPlus 6に続いてC++プログラムをタイプしました。実行すると結果は信じられないほどです。何か問題があると教えてください。私のislowerとisupperに何が問題なのですか?
#include <iostream>
#include <cctype>
int main()
{
using namespace std;
cout << "Enter your message and type @ to an end." << endl;
char ch;
int digit;
int alpha;
int lower;
int supper;
int punct;
cin.get(ch);
while (ch != '@')
{
if (isdigit(ch))
digit++;
else if (isalpha(ch))
alpha++;
else if (islower(ch))
lower++;
else if (isupper(ch))
supper++;
else
punct++;
cin.get(ch);
}
cout << "Digits: " << digit << endl << "Alpha: " << alpha
<< endl << "Lower: " << lower << endl << "Supper: "
<< supper << endl << "Puncts: " << punct << endl;
return 0;
}
そして、それはそれらを示した:
'iflower(ch)'ブロックの中で 'lower'と' supper'を数える必要があります。 – songyuanyao
私はあなたの変数を初期化することをお勧めします(これはあなたの問題です)。あなたが何を期待したのか、そしてそれが何をしたのかを小さな例でここにテキストで記述してください。私たちがそれに値する何かをしなければ、私たちを呪う必要はありません。 :) –
コードに含まれていても攻撃的ではない言語を質問に含めないでください。 –