There are 4 things wrong with this code (This assignment is written in C#). Plea
ID: 3886056 • Letter: T
Question
There are 4 things wrong with this code (This assignment is written in C#). Please correct the code and explain what you did to correct it:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DebugFixMethods
{
class Program
{
static void Main(string[] args)
{
(new Program()).run();
}
void run()
{
int choice = 0;
WritePrompt();
choice = ReadChoice();
WriteChoice(choice);
}
void Writeprompt()
{
Console.WriteLine("Please select a course for which you want to register by typing the number inside []");
Console.WriteLine("[1]IT 145 [2]IT 200 [3]IT 201 [4]IT 270 [5]IT 315 [6]IT 328 [7]IT 330");
Console.Write("Enter your choice : ");
}
int ReadChoice()
{
string s = "";
s = Console.ReadLine();
return (s);
}
void WriteChoice(choice)
{
Console.WriteLine("Your choice is {0}", Choice);
}
}
}
Explanation / Answer
Hi
I have fixed the issues and highighted the code changes below
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DebugFixMethods
{
class Program
{
static void Main(string[] args)
{
(new Program()).run();
}
void run()
{
int choice = 0;
WritePrompt();
choice = ReadChoice();
WriteChoice(choice);
}
void WritePrompt()
{
Console.WriteLine("Please select a course for which you want to register by typing the number inside []");
Console.WriteLine("[1]IT 145 [2]IT 200 [3]IT 201 [4]IT 270 [5]IT 315 [6]IT 328 [7]IT 330");
Console.Write("Enter your choice : ");
}
int ReadChoice()
{
string s = "";
s = Console.ReadLine();
return Convert.ToInt32(s);
}
void WriteChoice(int choice)
{
Console.WriteLine("Your choice is {0}", choice);
}
}
}
Output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.