20191207-do while练习,输入三次密码

  1. #include "stdafx.h"

  2. #include "iostream"

  3. #include "string"

  4. using namespace std;

  5. int main()

  6. {   string pwd="a123";

  7.     string n="";

  8.  int j=1;

  9.  do {

  10.  cout<<"请第"<<j<<"输入密码:";

  11.         cin>>n;

  12.  j++;

  13.  if (j>3)

  14.   {cout<<"3次输入错误,软件退出!"<<endl;

  15.   break;}

  16.  }

  17.  while(n!=pwd);

  18.  {

  19.    cout<<"输入正确,进入软件!"<<endl;

  20.  }

  21. }

//执行结果如下图,

 


程序思路:  这是一道DO WHILE的练习题,难点在于3次输入机会的判断。 

下一题: 

#include "stdafx.h"
#include "iostream"
#include "string"
using namespace std;
int main()
{  double a;
     cin>>a;
  if(!cin)
  {
       cin.clear();
    while(1)
    {    
     cout<<cin.get()<<endl;
    }
  }
}
输入:123 
输出:                                                      
原文地址:https://www.cnblogs.com/whcsrj/p/12928255.html