Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Rewrite the following code, using only if statements (NO \"else\"). There is an

ID: 3852152 • Letter: R

Question


Rewrite the following code, using only if statements (NO "else"). There is an error in the file-access portion of the code. What is it, and why is that an issue?: bool a = false, b = false: int c = 0, d = 0: if (a == true && b == false && c == 1 && d == 0) { StreamWriter writer1 = null: writer1 = new StreamWriter("C: OutputWritel.txt"): Console.SetOut(writer1): Console.WriteLine("True"): } else { StreamWriter writer2 = null: writer2 = new StreamWritert("C: OutputWrite2.txt"): Console.SetOut(writer2): Console.WriteLine("False"): }

Explanation / Answer

The code written without else statement is as follows:

bool a=false, b =false;
int c=0, d=0;

<......>

if(a==true && b==false && c==1 && d==0)
{
using(StreamWriter writer1=new StreamWriter("C:OutputWrite1.txt"));
Console.SetOut(writer1);
Console.WriteLine("True");
}

if(a == false && b==true && c==0 & d==1)
{
using(StreamWriter writer2=new StreamWriter("C:OutputWrite2.txt"));
Console.SetOut(writer2);
Console.WriteLine("False");
}

The error in the file accessing portion was that we were not implementing the using keyword in the program where we are witing each file from a directory.The above code is the orrect code for the following given bases.

Please rate the answer if it helped......Thankyou

Hope it helps...

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote