高手帮帮忙:C++程序代码改错
答案:1 悬赏:30
解决时间 2021-04-09 04:20
- 提问者网友:霸道又专情♚
- 2021-04-08 04:24
运行环境:Eclipse
#include <iostream>
#include <string>
using namespace std;
int main(){
string pw,chkpw,password,tmpw,tmpw1,tmpw2;
char t2;
int t1;
do{
cout<<"请选择操作:"<<endl;
cout<<"1.创建密码;"<<endl;
cout<<"2.修改密码;"<<endl;
cout<<"3.清除密码。"<<endl;
cout<<"请选择相应的数字:";
cin>>t1;
cout<<endl<<"按 y 确认,n重新选择:";
cout<<"按 y 确认,n重新选择:";
cin>>t2;
if(t2=='y') break;
}while(t2!='y');
switch(t1){
case 1:{ //1.创建密码
if(password=="") // 已有密码
cout<<"上次创建过密码!请选择操作:"<<endl;
cout<<"按 y 清除原有密码,重新创建;按 n 修改原有密码。";
cin>>t2;
switch(t2)
case 'n': switch(2);
************ // 这个地方错了!!!提示previously used here**************
case 'y': password="";
************ // 这个地方错了!!!提示previously used here**************
//输入两次密码以确认对比
do{
cout<<"请设置密码:";
cin>>pw;
cout<<endl;
cout<<"请再次输入密码:";
cin>>chkpw;
cout<<endl;
if(pw==chkpw) break;
}while(pw!=chkpw);//两次输入,不对重新输入
//两次输入,对就装入password中
password=pw;
}
case 2:{ //2.修改密码
if(password==""){ //判断原密码是否为空
cout<<"!非法! 原始密码没有创建!!"<<endl;
cout<<"是否创建密码?按 y 创建密码,按 n 退出";
cin>>t2;
switch(t2)
case 'n': exit(0);
************ // 这个地方错了!!!提示previously used here**************
case 'y': switch(1);
************ // 这个地方错了!!!提示previously used here**************
}
cout<<"请输入原密码:";
cin>>tmpw;
if(password==tmpw) cout<<"输入正确!"<<endl;
do{
cout<<"请输入新密码:";
cin>>tmpw1;
cout<<endl<<"请再次输入新密码确认:";
cin>>tmpw2;
if(tmpw2==tmpw1) break;
cout<<"两次输入不一样,请重新输入密码:";
}while(tmpw2==tmpw1);
password=tmpw1;
}
case 3:{ //3.清除密码
password="";
cout<<"清除密码成功!!!"<<endl;
cout<<"是否要创建新密码?按 y 创建新密码,按 n 退出。";
cin>>t2;
switch(t2)
case 'n': exit(0);
*************** // 这个地方错了!!!提示duplicate value*****************
case 'y': switch(1);
*************** // 这个地方错了!!!提示duplicate value*****************
}
}
}
字符串赋空值: password="" 提示previously used here
还有这个: case 'y': switch(1); 提示previously used here,后面的又提示duplicate value
最佳答案
- 二级知识专家网友:努力只為明天
- 2021-04-08 05:38
cin>>t2;
switch(t2)//这里要加个{吧
case 'n': exit(0);
switch(t2)//这里要加个{吧
case 'n': exit(0);
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯