Click here to Skip to main content
14,973,417 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
When I compile, I get the error as Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement in my while loop at conditional statement line. I am not sure what is it that I am missing.

What I have tried:

C#
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;


namespace UserNamespace
{
    class User
       {
       private string user_id;
       protected string user_password ;
    
       public User(string id,string pass )
          {
          user_id + id;
          user_password = pass;
          }

       public bool verifyLogin (string id ,string pass )
       {
          if (user_id.Equals(id) && user_password.Equals(pass))
           {
            Console.WriteLine("Succefull Login.Welcome!");
            return true;
           }
          else
             {
             Console.WriteLine("Invalid username or password.");
             return false;
             }
        }
            
        public void updatePass (String newPassword)
          {
          user_password = newPassword ;
          }

    class Administrator :User
       {
       private string admin_name;
        
       public Administrator (string name, string id ,string pass): base (id,pass)
          {
          this.admin_name = name;
          this.user_id = id;
          this.user_password = pass;
          }
       public void updatePassword (string newPassword )
          {
          updatePass(newPassword );
          }
       public void updateAdminName(string newName)
          {
          admin_name = newName;
          }
       }
        
       class Program
          {
          static void Main (string[] args)
        
          {
          Administrator login = new Administrator("","Student",""); 
          Console.Write("New Admin Name: ");
          string AdminName = Console.ReadLine();
          Console.Write("New Password: ");
          string newPassword =Console.ReadLine();
          login.updatePassword(newPassword);
        
          Console.WriteLine("\n Account sucessfully uploaded ");
          Console.Write("Your login ID Ps : " +login.user_id);
          Console.WriteLine("\n");
          Console.Write("Enter Your login ID: ");
          string loginID = Console.ReadLine();
            
          Console.Write ("Enter your Password:");
          string loginPassword = Console.ReadLine();
          login.verifyLogin(loginID,loginPassword);
                
          }
        }
     }
    }<pre>
Posted
Updated 22-Jun-21 20:38pm
v3

C#
public User(string id,string pass )
         {
          user_id=id;
         user_password = pass;
         }
   
v2
Comments
nikko tan 23-Jun-21 3:41am
   
Thankyou so much it very helpfull !!
I made some formatting-modifications to your code-snippet. Now you should be able to see where your mistakes are.
- Does each code-part belong to the position where it is placed ?
- Is Administrator and Programm really part of the class User ?

For future use :
Try to work with understandable formatting ...
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900