[問題] 小型提款機

看板C_and_CPP作者 (沒想過)時間13年前 (2012/03/21 23:29), 編輯推噓0(116)
留言8則, 5人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) Dev C++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 字串沒有如預期一般寫入檔案 餵入的資料(Input): 先以new建立帳號 帳號輸入aa 預期的正確結果(Expected Output): 理應出現psw的輸入訊息 錯誤結果(Wrong Output): error 程式碼(Code):(請善用置底文網頁, 記得排版) #include<iostream> #include<iomanip> #include<cmath> #include<string> #include<fstream> //紀錄型態 /* 帳號 型態(管理者、使用者) 密碼 金額 利率 */ using namespace std; int user(){ ifstream ip; ofstream op; int con=1; int result; char ina[100],inp[100]; char ac[100],str[100]; ip.open("data.txt"); op.open("data.txt"); //標頭 begin: cout<<"account:(enter new to create)"; cin>>ac; if(strcmp(ac,"new")!=0){ while(con==1) { ip >> str; if(strcmp(str,ac)==0 ) { result =1; cout <<"OK!"; break; } else if(strcmp(str,ac)!=0 && ~ip.eof()) { result =2; break; } } } else if(strcmp(ac,"new")==0) { cout<<"plese enter your new account:"; cin >> ina; op << ina << ' '; cout<<"please enter your new psd:"; cin >> inp; op << inp << ' '; goto begin; } if(result==1) { cout<<"ok"; } else { cout<<"error"; goto begin; } } 補充說明(Supplement): 這是我認為有錯的副函數 完整沒貼上來 麻煩各位了 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.114.220.123

03/21 23:34, , 1F
不是我看錯吧? label?
03/21 23:34, 1F

03/21 23:41, , 2F
因為想偷懶而寫的 我知道這很糟糕
03/21 23:41, 2F

03/21 23:54, , 3F
沒給完整的錯誤訊息, 有psw也有psd, 縮排想縮不縮的.
03/21 23:54, 3F

03/21 23:57, , 4F
抱歉了...我剛剛改過了 縮排問題是剛剛複製貼到記事本
03/21 23:57, 4F

03/21 23:57, , 5F
發生錯亂 情急之下先弄的
03/21 23:57, 5F

03/21 23:58, , 6F
我大概知道問題了 謝謝...
03/21 23:58, 6F

03/22 01:50, , 7F
置底有貼code的網頁
03/22 01:50, 7F

03/23 19:20, , 8F
竟然有goto
03/23 19:20, 8F
文章代碼(AID): #1FQVF9PH (C_and_CPP)