C++ 应该打印大小写的数字,但返回1并退出程序
在我用void函数编写程序之前,程序一直在运行。我不知道我把事情搞砸了。它返回1,不给出其他错误C++ 应该打印大小写的数字,但返回1并退出程序,c++,uppercase,lowercase,C++,Uppercase,Lowercase,在我用void函数编写程序之前,程序一直在运行。我不知道我把事情搞砸了。它返回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; low
#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;
}
#包括
#包括
使用名称空间std;
字符响应;
字符串s;
整数上限、下限、其他、计数;
无效capCheck(字符串);
int main()
{
计数=0;
上限=0;
下限=0;
做
{
cout只需在函数声明中更改void capCheck()
中的void capCheck(string s)
。它对我很有效
对代码的一些评论:尽量不要使用全局变量,并改进索引。在函数定义中放置
void capCheck(string s) {
// ...
}
看
提供的函数定义签名
void capCheck() {
// ...
}
与函数原型签名的实际声明不匹配
void capCheck(string);
“我不知道我在哪里搞砸了。它返回1,不给出其他错误。”
程序没有以您发布代码的形式编译。生成过程可能提前停止(请注意,main()
函数中没有任何路径返回1
).好吧,那段代码甚至没有为我编译。您对capCheck
的声明和定义不匹配,您应该学会在不使用全局变量的情况下执行此操作。@πάνταῥεῖ 当然!我这么说是因为他/她评论了我的答案而不是你的:)哈哈,对不起,伙计们。这不会让我投票,因为我的声望不够高