Sign in to follow this  
Philler

Problem with C#

Recommended Posts

Hi, I'm new here and I have a question. I'm setting up a real small program, but the problem is when it is supposed to stop working, the lines with messages keep growing, not inteted. this is the code (its a C# code run in Windows Console) and if you run it you will probably understand my (a bit noobisch) issue better than i can explain it. Some parts are in dutch, my appologies for that. Thanks anyway for reading this. Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Vragenlijst
{
    class Program
                                                                            
    {
        static void Main(string[] args)
        {
            Hallo();                                                        
                                                                            
            Console.Write("Please enter accountname, to log in to Philippe's PC: ");                    
            string naam = Console.ReadLine();                               
            while (naam != "")                                              
                                                                            
            {
                Welkomgebruiker(naam);                                      
                Console.Write("Please enter password: ");                   
                string antwoord = Console.ReadLine();                      
                                                                                   
                while (antwoord != "")                                      
                {
                    vraag1(antwoord);
                    Console.Write("You are succesfully logged on to Philler's computer,");
                    Console.Write("now please enter the name of Philippe's Pet to gain acces to his 'mijn documenten' section: ");
                    string deel2 = Console.ReadLine();

                    while (deel2 != "")
                    {
                        vraag2(deel2);
                        vraag2(deel2);
                        Ingelogd();
                    }
                 }                
            }

        }
        static void Hallo()
        {
            Console.WriteLine("Logging on to pc,");
        }
        static void Welkomgebruiker(string wie)
        {
            string bericht = Tegenwie (wie);
            Console.WriteLine(bericht);
        }
        static string Tegenwie(string wie)
        {
            string bericht;
            if (wie == "Philler")
            {
                bericht = "Accountname correct";
            }
            else
            {
                bericht = "I am sorry please retype your name " + wie;
            }
            return bericht;
        }
        static void vraag1 (string oplossing1)
        {
            string wat = Vraag1 (oplossing1);
                Console.WriteLine (wat);
        }
        static string Vraag1(string oplossing1)
        {
            string wat;
            if (oplossing1 == "123")
            {
                wat = "congratualions, password correct, hacker.";
            }
            else
            {
                wat = "Please retry this is not a valid password: " + oplossing1;
            }
            return wat;
        }
        static void vraag2(string oplossing2)
        {
            string uitkomst2 = Vraag2(oplossing2);
            Console.WriteLine(uitkomst2);
        }
        static string Vraag2(string oplossing2)
        {
            string uitkomst2;
            if (oplossing2 == "elounda")
            {
                uitkomst2 = "You are now logging in to Philippe's mijn documenten, using password: " + oplossing2;
            }
            else
            {
                uitkomst2 = "Please restart programm, this isnt correct: " + oplossing2;
            }
            return uitkomst2;
        }
        static void Ingelogd()
        {
            Console.WriteLine("You are succesfully logged in to Philippe's Mijn documenten");
        }
    }
}

[Edited by - Philler on March 8, 2008 2:01:56 PM]

Share this post


Link to post
Share on other sites
Not sure what you mean by "the lines with messages keep growing", but I can see your program is going to loop forever since there's no way to exit the first while loop.


string naam = Console.ReadLine();
while (naam != "")
{
// other stuff
}


The problem here is that naam(name) never changes inside the loop, the user only enters the name when the program starts. If you only want the program to run once then change it to:


string naam = "";
while (naam == "")
{
naam = Console.ReadLine();
}
// other stuff


Also please use either [code][/code] or [source][/source] tags in the future. The forum destroys any formatting which makes that last area of your program with all the functions difficult to read.

Share this post


Link to post
Share on other sites
thanks alot, indeed with "the lines keep growing" I meant it kept on looping, thanks alot for the tips now it finally works :D, and also thanks for the code/source tags, I'll keep in mind using them!

Again thanks a lot

Philler

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this