史萊姆論壇

史萊姆論壇 (http://forum.slime.com.tw/)
-   軟體應用問題討論區 (http://forum.slime.com.tw/f5.html)
-   -   c++語法程式問題 (http://forum.slime.com.tw/thread99667.html)

longmai 2004-03-12 12:02 AM

c++語法程式問題
 
請問各位高手們!

若想用c++的語法寫出一到密碼鎖的程式!(陣列與字串)

也就是大概來說->例如:先設一定4位數字為密碼

寫出一套程式~

只能讓輸入密碼者輸入3次密碼!

若第3次沒還有成功的話!

程式即顯示"密碼已鎖"

也就是已經沒辦法解開的意思!

大概類似提款卡的一套程式!

希望各位高手朋友們有興趣的話可以一起討論喔!


我使用的是這套c++軟體->Dev C++是免費軟體可從http://www.bloodshed.net/devcpp.html 下載
最新的版本與相關的資源

indark 2004-03-12 03:06 AM

#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

starforce 2004-03-13 03:01 PM

剛剛 幫忙測ㄌ一下
有兩個錯誤
1.沒有呼叫STRING
2.counter ++: 是分號不是冒號
一個小BUG
要求為輸入三次 所以條件中的=要去掉

這是個人的測試結果啦

snoopy 2004-03-14 02:33 AM

編譯器不同 標頭檔也會不同喔

例如說 DVE C 跟 Visual C++就不同

可能錯誤原因

indark 2004-03-14 04:30 AM

引用:

原文由 starforce 所發表
1.沒有呼叫STRING

What compiler do you use?
引用:

2.counter ++: 是分號不是冒號

The following has been tested with Dev 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.

『服務條款』

* 有問題不知道該怎麼解決嗎?請聯絡本站的系統管理員 *


SEO by vBSEO 3.6.1