我有程序工作,直到我用void函數編寫它。我不知道我在哪裏搞砸了。它返回1,並沒有給出其他錯誤。假設打印大寫和小寫數字,但返回1並退出程序
#include <iostream>
#include <string>
using namespace std;
char response;
string s;
int upper, lower, other, count;
void capCheck(string);
int main()
{
count = 0;
upper = 0;
lower = 0;
do
{
cout<<"Get the number of upper and lower case letters in your sentence!!"<<endl;
cout<<endl;
cout<<"Type your sentence below without spaces.."<<endl;
cin>>s;
capCheck(s);
cout<<"Would you like to continue? Y/N"<<endl;
cin>>response;
}while(response == 'y' || response == 'Y');
return 0;
}
void capCheck()
{
while(s[count] != 0)
{
if(s[count] >= 'a' && s[count] <= 'z')
{
lower++;
count++;
}
else if (s[count] >= 'A' && s[count] <= 'Z')
{
upper++;
count++;
}
else
other++;
}
cout<<"The number of uppercase letters are: "<<upper<<endl;
cout<<"The number of lowercase letters are: "<<lower<<endl;
}
那麼代碼甚至不爲我編譯。 – 2014-09-30 19:37:19
你的聲明和'capCheck'的定義不匹配,你應該學會在不使用全局變量的情況下做到這一點。 – crashmstr 2014-09-30 19:38:13