What's new

C# Pa-help naman po mga master

ja_mario14

Addict
Joined
Apr 1, 2022
Posts
102
Reaction
16
Points
89
using System;

class LabExercise2
{
static void Main() {

// Correct Credential
string username = "Juan";
string password = "Santos";

//User input username and password
Console.Write("\nUsername : ");
string un = Console.ReadLine();

Console.Write("Password : ");
string pw = Console.ReadLine();


//Condition

if(un.Equals(username) && pw.Equals(password))
{
Console.WriteLine("\nSuccessfully Login.");
}

else if(!un.Equals(username) || pw.Equals(password))
{
Console.WriteLine("\nYou entered an invalid user name.");
}

else if(un.Equals(username) || !pw.Equals(password))
{
Console.WriteLine("\nYou entered an invalid password.");
}

else if(un.Equals(username) && pw.Equals(password))
{
Console.WriteLine("\nYou entered an invalid user name and password.");
}
}
}



===========================================================================


Pls help. hindi ko po makuha yung tamang return.
anu po yung mali sa code? or tama po ba yung code structure and logic.


PS. Sorry po inilagay ko lang sa text box yung code, wala po kasing option sakin para ilagay yung code ko po sa code box.


Thank you in advance. Gobless us.

note.png
 

Attachments

Try

C#:
// Correct Credential
string username = "Juan";
string password = "Santos";

//User input username and password
Console.Write("\nUsername: ");
var un = Console.ReadLine();

Console.Write("Password: ");
var pw = Console.ReadLine();


//Condition

if (un == username && pw == password) {
    Console.WriteLine("\nSuccessfully Login.");
} else if (un != username && pw == password) {
    Console.WriteLine("\nYou entered an invalid user name.");
} else if (un == username && pw != password) {
    Console.WriteLine("\nYou entered an invalid password.");
} else if (un != username && pw != password) {
    Console.WriteLine("\nYou entered an invalid user name and password.");
}

Output:



Username: asd
Password: asd

You entered an invalid user name and password.


Username: Juan
Password: asdasd

You entered an invalid password.


Username: asdasdsa
Password: Santos

You entered an invalid user name.


Username: Juan
Password: Santos

Successfully Login.
 
Last edited:
Try

C#:
// Correct Credential
string username = "Juan";
string password = "Santos";

//User input username and password
Console.Write("\nUsername: ");
var un = Console.ReadLine();

Console.Write("Password: ");
var pw = Console.ReadLine();


//Condition

if (un == username && pw == password) {
    Console.WriteLine("\nSuccessfully Login.");
} else if (un != username && pw == password) {
    Console.WriteLine("\nYou entered an invalid user name.");
} else if (un == username && pw != password) {
    Console.WriteLine("\nYou entered an invalid password.");
} else if (un != username && pw != password) {
    Console.WriteLine("\nYou entered an invalid user name and password.");
}

Output:



Username: asd
Password: asd

You entered an invalid user name and password.


Username: Juan
Password: asdasd

You entered an invalid password.


Username: asdasdsa
Password: Santos

You entered an invalid user name.


Username: Juan
Password: Santos

Successfully Login.



okay na po naayos ko na po.

Thank you po Master. God bless
 

Similar threads

Back
Top