Question

//Need some help here please. :) Fix four flaws in the following program. // Fix four...

//Need some help here please. :)

Fix four flaws in the following program.


// Fix four flaws

// Note: there are more than four flaws!

static void Main(string[] args)

{

    string userName;

    Console.WriteLine("Please enter your name.");

    userName = Console.ReadLine();

    doLotsOfStuff(userName);

}

public void DoLotsOfStuff(string n)

{

    bool guest;

    if (n = "Student")

    {

        Console.WriteLine("Welcome " + n);

        guest = false;

    }

    else if (n = "Admin")

    {

        Console.WriteLine("Welcome " + n);

        guest = false;

    }

    else

    {

        Console.WriteLine("Welcome " + n);

        guest = true;

    }

    if (n.Length < 5)

        Console.WriteLine("User name too short.");

    if (guest == true)

        Console.WriteLine("You're a guest.");

    foreach (char trundleThroughItAll in n)

        Console.Write(trundleThroughItAll);

    Console.WriteLine();

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

using System;

public class Test
{
   // Fix four flaws

// Note: there are more than four flaws!

static void Main(string[] args)

{

string userName;

Console.WriteLine("Please enter your name.");

userName = Console.ReadLine();

DoLotsOfStuff(userName);// Flaw 1 : Name of function is incorrect , d is case sensitive

}

public static void DoLotsOfStuff(string n) // Flaw 2: function should be declared static to call it without object reference

{

bool guest;

if (n == "Student") // Flaw 3: == should be used for comparisor with if as = is assignment operator

{

Console.WriteLine("Welcome " + n);

guest = false;

}

else if (n == "Admin")// Flaw 4: == should be used for comparisor with if as = is assignment operator

{

Console.WriteLine("Welcome " + n);

guest = false;

}

else

{

Console.WriteLine("Welcome " + n);

guest = true;

}

if (n.Length < 5)

Console.WriteLine("User name too short.");

if (guest == true)

Console.WriteLine("You're a guest.");

foreach (char trundleThroughItAll in n)

Console.Write(trundleThroughItAll);

Console.WriteLine();

}


}

Do ask if any doubt. Please up-vote.

Add a comment
Know the answer?
Add Answer to:
//Need some help here please. :) Fix four flaws in the following program. // Fix four...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT