2016-05-30 9 views
-2
#include "stdafx.h" 
#include <iostream> 
#include <cstdlib> 
#include <string> 
using namespace std; 
string checkpass(string password1) 
{ 
    string rightpass = "aimen"; 
    string errormsg2; 
    if (password1 == rightpass) 
    { 
     errormsg2 = "Right"; 
    } 
    else{errormsg2 = "No";} 
    return errormsg2; 
} 
int main() 
{ 
    string password; 
    string errormsg; 
    cout << "Type the password"; 
    loop: 
    getline (cin,password); 
    errormsg == checkpass(password); 
    if (errormsg=="Right") 
    { 
     cout << "Admitted" << endl; 
    } 
    else { 
     goto loop; 
    } 
    system("pause"); 
    return 0; 
} 

コンソールに「Admitted」と表示されません。それは始まりますが、私がコンソールの言葉を入れた後、繰り返し何も起こりません。ループを作成する際の問題

私はあなたの援助を要求します。ありがとうございました。

+0

gotoは一般的に眉をひそめます。これに関する議論については、http://stackoverflow.com/questions/3517726/what-is-wrong-with-using-gotoを参照してください。おそらく、whileループが良いでしょう。 – Ian

答えて

1

あなたはerrormsg == checkpass(password)と比較しています。 1つの=記号を割り当てる必要があります。

+0

ああ、ありがとう、私はそれを語らなかった。 – user2952487

関連する問題