Resolved If Commands Problem!!!!

nikegamerjjjj

Member
Joined
Aug 2, 2021
Messages
11
Programming Experience
1-3
My Code:
using System;

namespace NikPoloTerminal_for_C_
{
    class Program
    {
        static void Main(string[] args)
        {
            void space() {
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("");
            }
      
            Console.WriteLine("NikPolo Command Terminal \nv.0.2");

            string user, pswrd, checkuser, checkpswrd;
  
            bool whileterminal = true;
            bool while_login = true;
            bool while_pswrd = true;
            bool while_user = true;

            while (while_user) {
                Console.Write("Write new username: ");
                user = Console.ReadLine();
                Console.Write("Save username? Write yes or no: ");
                string yesno;
                yesno = Console.ReadLine();
                if ("yes" == yesno || "y" == yesno) {
                    while_user = false;
                    Console.WriteLine("\nSaved!");
                }
                else {
                    continue;
                }
            }
            while (while_pswrd) {
                Console.Write("Write new password: ");
                pswrd = Console.ReadLine();
                Console.Write("Save password? Write yes or no: ");
                string yesno2;
                yesno2 = Console.ReadLine();
                if ("yes" == yesno2 || "y" == yesno2) {
                    while_pswrd = false;
                    Console.Write("\nSaved!");
                }
                else {
                    continue;
                }
            }
            space();

            while (while_login) {
                Console.Write("Login: ");
                Console.Write("Write username: ");
                checkuser = Console.ReadLine();
                Console.WriteLine();
                Console.Write("Write password: ");
                checkpswrd = Console.ReadLine();
                Console.WriteLine();
                if (user == checkuser) {
                    if (checkpswrd == pswrd) {
                        space();
                        space();
                        while_login = false;
                        Console.WriteLine("Login Complete!"); 
                    }
                    else {
                        Console.WriteLine("Incorrect password or username");
                        Console.WriteLine();
                    } 
 
                }
                else {
                    Console.Write("Incorrect username or password");
                    Console.WriteLine();
                }
            }
        }
    }
}
My Problem in code is where i highlighted, i tried searching but i didnt understand it generally. Problem is that my code can't use variable "user" cause its not local, What does it mean? Much help Apperciated!!

Edit: It supposed to be highlighted, but the Problem is in line 134 and 135 where variable "user" and "pswrd" is a problem!
 
Last edited:

JohnH

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
1,362
Location
Norway
Programming Experience
10+
If you highlight the error line in Error List and press F1 it takes you directly to this help page:

You can initialize those variables to null
 
Last edited:

nikegamerjjjj

Member
Joined
Aug 2, 2021
Messages
11
Programming Experience
1-3
If you highlight the error line in Error List and press F1 it takes you directly to this help page:

You can initialize those variables to null
I don’t know what variable is about to have because only way I going to know it is that I must use input, but if I don’t have input, what should it supposed to be in variable value?
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
4,431
Location
Chesapeake, VA
Programming Experience
10+
C#:
string user = null;
string pswrd = null;
string checkuser = null;
string checkpswrd = null;

I highly, highly, highly recommend that you step back and take time to learn the language from a book or tutorial. Right now it feels like you've learned the language from YouTube videos.
 

nikegamerjjjj

Member
Joined
Aug 2, 2021
Messages
11
Programming Experience
1-3
C#:
string user = null;
string pswrd = null;
string checkuser = null;
string checkpswrd = null;

I highly, highly, highly recommend that you step back and take time to learn the language from a book or tutorial. Right now it feels like you've learned the language from YouTube videos.
Thank you again Skydiver! Yeah I know it, but I like to try things self, of course I don’t any tutorial will tell about uninitialized variables. Who knows…. I like to be self-taught…that’s all I know…
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
4,431
Location
Chesapeake, VA
Programming Experience
10+
If you want to be self-taught it's time to start reading the C# language guide and language reference. That's how I taught myself C# many years ago.
 

JohnH

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
1,362
Location
Norway
Programming Experience
10+

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
4,249
Location
Sydney, Australia
Programming Experience
10+
Okay, do you have any links to C# Language Guide you learned on?
What exactly is preventing you typing "c# language guide" into a search engine? You need to adjust your attitude to ALWAYS do what you can for yourself first, then ask questions only if you need to. If you had done that then you'd realise that THE C# language guide is specifically the official documentation from Microsoft, so not something you need someone else to find for you.
 

nikegamerjjjj

Member
Joined
Aug 2, 2021
Messages
11
Programming Experience
1-3
What exactly is preventing you typing "c# language guide" into a search engine? You need to adjust your attitude to ALWAYS do what you can for yourself first, then ask questions only if you need to. If you had done that then you'd realise that THE C# language guide is specifically the official documentation from Microsoft, so not something you need someone else to find for you.
But what is preventing YOU, from being not aggressive?? What? I don’t know what guide is worst and what is best? Do YOU! think that I’m an excellent programmer? No. Answer is no.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
4,431
Location
Chesapeake, VA
Programming Experience
10+
There is only one C# language guide provided by Microsoft. It's why @jmcilhinney put 'THE' in capital letters.
 

cbreemer

Well-known member
Joined
Dec 1, 2021
Messages
49
Programming Experience
10+
So, let me get this straight.... You take up C# programming without bothering to look at the documentation or follow some of the many available tutorials. You just cobble something together, and when it does not work like you want, you go to a forum and ask (or rather, demand) help, not even explaining the exact problem, saying you're a newbie and like to work out things for yourself. And when the endlessly patient and helpful staff members politely point out this is not how things work, you get on your high horse and call them aggressive. Way to go, gamer. If this is your method of learning and getting help, good luck with that.
 

ProtekNickz

Member
Joined
Jan 13, 2022
Messages
6
Programming Experience
5-10
Dear nikegamerjjjj, This forum and others like it, love to help people with their coding problems, I've had help from their other forum "VBdotnet forums" many times, What they are not here to do, is give you code so you just Copy & Paste it in, they try to help you to figure it out by giving you the Syntax to look up, This in turn will help you to remember the next time, Like others on here have said, Find a Book read it and start from their, any book will be suffice as long as its C# "Csharp", No book will learn you wrong you will just learn differently for each book you read, You could even Buy eBooks to work from and use a tablet if you have no second screen, which isn't needed, It depends on how you wish to learn, and that's it you wish to learn, jmcilhinney isn't being angry with you nor is anyone else, they're just trying to guide you in to the right way of thinking, and not acting like a 12 y/o girl, I wish i could take you back to the 1980's to learn on a PC back then, No Internet at all and the local Library's were terrible for coding books so you had to use your head and play with code for hours and days, and read what little documentation their was supplied with each tool set, But now you have the Vast Internet and Search Engines and Library's online all at your fingertips, use them soak up the information and progress like we should do, Not complain that no one has helped you even when they did in their original post, sorry it's long winded, and by all means don't take this as me being hateful or angry, this is just common sence.

Yours ProtekNickz :).
 
Top Bottom