本应打印大小写数字,但返回1并退出程序
Supposed to print number of upper and lowercase but returns 1 and exits program
在用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;
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;
}
只需在函数声明中将void capCheck()
更改为void capCheck(string s)
即可。它对我来说很好。
对代码的一些评论:尽量不要使用全局变量,并提高独立性。
在您的函数定义中放入
void capCheck(string s) {
// ...
}
观看现场演示。
提供的功能定义签名
void capCheck() {
// ...
}
与函数原型的签名的实际声明不匹配
void capCheck(string);
"我不知道我在哪里搞砸了。它返回1,没有其他错误。"
该程序没有按照您发布代码的形式进行编译。构建过程可能提前停止(请注意,main()
函数中没有任何返回1
的路径)。
相关文章:
- 为什么异常不退出程序?
- 我不断收到 [错误] ID 返回 1 退出状态错误,但看不到问题所在
- 试图在崇高中奔跑. 错误 已发生: 收集2.exe: 错误: ld 返回 1 退出状态
- 虽然循环在使用回车键时不退出程序
- C++ collect2:错误:ld 返回 1 退出状态
- 找不到 -llibmysqld Collect2.exe:错误:ld 返回 1 退出状态
- 如果 I/O read() 处于阻塞阶段,如何使用 Ctrl+C 退出 C++ 程序?
- 捕获异常后如何退出程序执行
- 每次我要使用外部资源时,我都会得到:collect2。exe:错误 ld 返回 1 退出状态
- 在C++中使用exit()退出程序有问题吗
- 从函数打印 CLI 帮助消息后,我应该如何干净地退出 C++ 程序?
- 如何实现否定用户输入退出程序和打印列表?
- gdb 退出:程序接收信号 SIGILL,使用 gcc / intel_mkl / gfortran -mavx 编译的
- 试图调节我的 do-while 以停止在终端中退出程序.菜单不会根据需要循环使用当前语句
- 使用类[错误] LD返回1退出状态
- 如何在C 中按ENTER/返回键时退出程序循环
- 简单c++程序Id的问题返回1退出状态
- 本应打印大小写数字,但返回1并退出程序
- 返回菜单并退出程序
- 使用AWS-cpp-sdk时,在退出程序之前等待异步调用返回