C++程式設計項目開發——銀行自動提款機(三)

來源:互聯網
上載者:User

在輸入密碼時,實現有限次密碼輸入的限制,如果三次都沒有輸入正確,程式將直接退出,不允許使用者繼續操作。

#include <iostream>#include <string>using namespace std;int main(){string pwd;int cLogin=0;do {cout<<"\n請輸入密碼:\n";cin>>pwd;if (pwd!="123"){cLogin+=1;}else{cout<<"輸入正確!";break;}cout<<"每天只有三次機會,今天還有輸入密碼的次數:"<<3-cLogin<<endl;} while (cLogin<3);system ("Pause");}

在這裡迴圈可以使用其他,我用的是do{}while(),for迴圈也可以在這裡我就不多寫了,大家可以動手試下。畢竟能力有限,如果哪有寫的不好的地方,大家可以指出來,一起學習。謝謝。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.