![]() |
c++語法程式問題
請問各位高手們!
若想用c++的語法寫出一到密碼鎖的程式!(陣列與字串) 也就是大概來說->例如:先設一定4位數字為密碼 寫出一套程式~ 只能讓輸入密碼者輸入3次密碼! 若第3次沒還有成功的話! 程式即顯示"密碼已鎖" 也就是已經沒辦法解開的意思! 大概類似提款卡的一套程式! 希望各位高手朋友們有興趣的話可以一起討論喔! 我使用的是這套c++軟體->Dev C++是免費軟體可從http://www.bloodshed.net/devcpp.html 下載 最新的版本與相關的資源 |
#include<iostream>
using namespace std; int main() { bool isMatch = false; string userInput, pass = "defaultpass"; int counter = 0; do{ cin >> userInput; counter ++: isMatch = (userInput == pass); } while( !isMatch && (counter <= 3)); if(!isMatch) cout << "密碼已鎖" << endl; return 0; } :P should be right, but didn't check to make sure if correct |
剛剛 幫忙測ㄌ一下
有兩個錯誤 1.沒有呼叫STRING 2.counter ++: 是分號不是冒號 一個小BUG 要求為輸入三次 所以條件中的=要去掉 這是個人的測試結果啦 |
編譯器不同 標頭檔也會不同喔
例如說 DVE C 跟 Visual C++就不同 可能錯誤原因 |
引用:
引用:
no error messages were generated, so it should be correct this time, ------------------------------------------------ #include<iostream> using namespace std; int main() { bool isMatch = false; string userInput, pass = "defaultpass"; int counter = 1; cout << "Please enter your password" << endl; cin >> userInput; for(int counter = 1; counter <=3 && !(userInput == pass); counter++) { cout << "Please try again" << endl; cin >> userInput; } if(!isMatch) cout << "pass locked" << endl; return 0; } |
所有時間均為台北時間。現在的時間是 09:21 PM。 |
Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2025, Jelsoft Enterprises Ltd.
『服務條款』
* 有問題不知道該怎麼解決嗎?請聯絡本站的系統管理員 *