想请高手帮忙指教!

来源:百度知道 编辑:UC知道 时间:2024/05/31 08:18:18
想设计一个程序,思路如下;
密码是100,当输入正确后显示输入正确,然后跳出.你只有三次机会,如果第一次没对,显示"错误,请再试试",第二次不对,显示"加油,再试试"三次不对,显示"game over"然后跳出!!而我设计的总是跳回原来的地方!!
十分感谢各位帅(靓)虾对我小虾米的支持和帮助!!!昨天小弟又往后翻了一下书,刚好看到跳转语句这一篇,灵机一闪,终于被我弄出来了!!呵呵,不过我也决不食言,一定会从各位的答案中选出一个的,再次感谢各位!!!
我完成的代码如下:
#include <iostream>
using namespace std;
double main()
{
double a;
cout<<"三次机会输入密码,开始:";
do{
cin>>a;
if(a==100)
goto last;

else if(a!=100)
cout<<"错误,请再试试:";
cin>>a;
if(a==100)
goto last;

else if(a!=100)
cout<<"加油,再试试:";
cin>>a;
if(a==100)
last: cout<<"恭喜,答对了!"<<'\n';

else if(a!=100)
cout<<"game over"<<'\n';
break;
}while(a!=100);
}

#include <iostream>
int main()
{
int *p=100; /*密码*/
int count=0,code; /*计数器和输入数据*/

while (count != 2)
{switch (count)
case 0:
std::cout << "输入密码: " << std::endl;
std::cin >> code;
if (code=*p)
break;
case 1:
std::cout << "错误,请再试试:" << std::endl;
std::cin >> code;
if (code=*p)
break;
case 2:
std::cout << "加油,再试试:" <<std::endl;
std::cin >> code;
if (code=*p)
break;
default:
}
}

#include<stdio.h>
#include<string.h>
#define PASSWORD "100"
int main()
{
int ag=0;
char pw[10];
printf("enter the password:");
gets(pw);
if(strlen(pw)==3&&memcmp(pw,PASSWORD,3)==0)
{
printf("输入正确!\n");
return 0;
}
else printf("错误,请再试试!\n");
gets(pw);
if(s