What's new

Closed Pahelp naman po sa c++ coding mga lodi

Status
Not open for further replies.

itsmeaze

Honorary Poster
Established
Write a program that will input a string as a password and determine if the password is valid or invalid.
 
Kung di ka marunong mag simula ka dito:
C++ Syntax: You do not have permission to view the full content of this post. Log in or register now.
C++ Output: You do not have permission to view the full content of this post. Log in or register now.
C++ Variables: You do not have permission to view the full content of this post. Log in or register now.
C++ User Input: You do not have permission to view the full content of this post. Log in or register now.
C++ If/Else: You do not have permission to view the full content of this post. Log in or register now.

May mga example naman yan saka basic lang yan at madaling maintindihan kahit 0 knowledge ka sa C++
Pag alam mo na ang 5 na yan madali nalang yan, isang string variable and if else lang kailangan mo diyan.
 
#include <iostream>
#include <string>

using namespace std;

int main () {

string password;

cout<<"Enter a password: ";
getline (cin,password);


if(password==password){
cout<<"Valid password.";
}
else {
cout<<"Invalid password!";
}
return 0;
}



eto po kase code ko eh puro valid po lumalabas. dapat pg nag input ng integer invalid po sana. kaso nagiging valid padin
 
#include <iostream>
#include <string>

using namespace std;

int main () {

string password;

cout<<"Enter a password: ";
getline (cin,password);


if(password==password){
cout<<"Valid password.";
}
else {
cout<<"Invalid password!";
}
return 0;
}



eto po kase code ko eh puro valid po lumalabas. dapat pg nag input ng integer invalid po sana. kaso nagiging valid padin
Good at gumawa ka ng sarili mong code.
Yung ilagay mo sa if condition mo ay ganito
C++:
if (password == "yung ilalagay mo dito ay yung gusto mong maging password")

// example
    
if (password == "1234")

So sa ibinigay kong example 1234 yung password, so pag hindi 1234 yung ininput ng user mag iinvalid yung output. And if 1234 ininput ng user edi yung if statement yung mag eexecute at valid password lalabas
 
Thank you po.
Pero di po ba possible na kahit anong string ang iinput tapos valid parin po. saka lang po magiging invalid pag integer ang iniput
 
galeng! Pano yan lods?
C++:
#include<iostream>
using namespace std;

int main ()
{
    
    string password;
    char ch;

    here:
    cout << "Enter your password: ";

    while (getline(cin, password))
    {
        for (int i = 0; i < password.length(); i++) {
    
            ch = password.at(i);
    
            
            if (!(( ch >= 'a' && ch <= 'z' )||( ch >= 'A' && ch <= 'Z' ))) {
                cout << "Error!" << endl << endl;
                goto here;
                
                
            } else {
                cout << "The password you entered is valid." << endl << endl;
                goto here;
                
            }
         }
     }
    
    
}

Gawin mo na yan na reference.
 
Status
Not open for further replies.

Similar threads

Back
Top