求好心人指教

活宝_往昔 2013-05-08 09:37:37
#include <iostream>
using namespace std;
char changeChar(char temp)
{
temp='temp'-'A'+'a';
cout<<"转化后的字母是:"<<temp<<endl;
return temp;
}
int main()
{
char temp;

cout<<"请输入一个小写字母:"<<endl;
cin>>temp;
cout<<"输出刚才输入的字母:"<<temp<<endl;
changeChar(temp);
return 0;
}为什么这个程序不能讲一个小写字母转换为大写字母
...全文
170 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
zcious 2013-05-14
  • 打赏
  • 举报
回复
你程序有误,2楼为正解。。。
hex_code 2013-05-13
  • 打赏
  • 举报
回复
temp应该没有单引号,小转大写应该是temp - 'a' + 'A' http://bugcode.com.cn
anshiny 2013-05-13
  • 打赏
  • 举报
回复
char changeChar(char temp){
	temp = temp-'a'+'A';
	cout<<"转化后的字母是:"<< temp <<endl;
	return temp;
}
就是那个党伟 2013-05-13
  • 打赏
  • 举报
回复
#include <iostream>
using namespace std;

char changeChar(char temp)
{
	temp=temp-32;//a-A = 32
	//temp = temp - 'a' + 'A';
	cout<<"转化后的字母是:"<<temp<<endl;
	return temp;
}
int main()
{
	char temp;	
	cout<<"请输入一个小写字母:"<<endl;
	cin>>temp;
	cout<<"输出刚才输入的字母:"<<temp<<endl;
	changeChar(temp);

	return 0;
}
ForestDB 2013-05-09
  • 打赏
  • 举报
回复
小写字母转换为大写字母 不应该是 temp='temp'-'A'+'a'; 而应该是 temp=temp-'a'+'A';
deidaro 2013-05-09
  • 打赏
  • 举报
回复
引用 1 楼 wangxing199920608 的回复:
我刚改了下函数数组函数的变量 重新定义了一个局部变量a就可以转换了 想问问变量在C++函数里是怎么用的 求解释的清楚点。看过书了,感觉还是模模糊糊的。。为什么第一次的就不能输出字母
松哥是好人 2013-05-08
  • 打赏
  • 举报
回复
抱歉,上面写得莫名其妙 单引号表示一个字符;而字符串用""。
松哥是好人 2013-05-08
  • 打赏
  • 举报
回复
'temp'不要加单引号,temp=temp-'A'+'a'; 单引号表示一个字符,注意是一个字符是字串了,而字符用""。 另外你给temp这个变量加了'',编译器也认不出来这是个什么
hugett 2013-05-08
  • 打赏
  • 举报
回复

#include <iostream>
using namespace std;
char changeChar(char temp)
{
	temp=temp-'a'+'A';//这里错了。。改成这样。。
	cout<<"转化后的字母是:"<<temp<<endl;
	return temp;
}
int main()
{
	char temp;

	cout<<"请输入一个小写字母:"<<endl;
	cin>>temp;
	cout<<"输出刚才输入的字母:"<<temp<<endl;
	changeChar(temp);
	return 0;
}
活宝_往昔 2013-05-08
  • 打赏
  • 举报
回复
我刚改了下函数数组函数的变量 重新定义了一个局部变量a就可以转换了 想问问变量在C++函数里是怎么用的 求解释的清楚点。看过书了,感觉还是模模糊糊的。。为什么第一次的就不能输出字母

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧