Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

So I am currently fixing a code that my professor gave out. Our job is to find the errors, fix them and then while debugging,

So I am currently fixing a code that my professor gave out. Our job is to find the errors, fix them and then while debugging, we are allowed to "register" for 3 classes, 9 credit hours. The number of classes is only 1-7, 3 credit hours each class. Each class registered are one at a time. If you input a number more than 7 it comes up as an error. I can't seem to get it to load the course "IT ###" after "Registered for." Anything I try, I can't seem to get the correct output. This is a C# class I'm in by the way. Help!!!

Here's the code I have right now:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace ConsoleRegisterStudent { class Program { static void Main(string[] args) { (new Program()).Run(); }

void Run() { int choice; int firstChoice = 0, secondChoice = 0, thirdChoice = 0; int totalCredit = 0; string yesOrNo = "";

System.Console.WriteLine("Amanda Ackerman's Copy");

do { WritePrompt(); choice = Convert.ToInt32(Console.ReadLine());

switch (ValidateChoice(choice, firstChoice, secondChoice, thirdChoice, totalCredit)) { case -1: Console.WriteLine("Your entered selection {0} is not a recognized course.", choice); break; case -2: Console.WriteLine("You have already registerd for this {0} course.", ChoiceToCourse(choice)); break; case -3: Console.WriteLine("You can not register for more than 9 credit hours."); break; case 0: Console.WriteLine("Registration Confirmed for course {0}.", ChoiceToCourse(choice)); totalCredit += 3; if (firstChoice == 0) firstChoice = choice; else if (secondChoice == 0) secondChoice = choice; else if (thirdChoice == 0) thirdChoice = choice; break; }

WriteCurrentRegistration(firstChoice, secondChoice, thirdChoice, totalCredit); Console.Write(" Do you want to try again? (Y|N)? : "); yesOrNo = (Console.ReadLine()).ToUpper(); } while (yesOrNo == "Y");

Console.WriteLine("Thank you for registering with us"); }

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 ValidateChoice(int choice, int firstChoice, int secondChoice, int thirdChoice, int totalCredit) { if (choice < 1 || choice > 7) return -1; else if (choice == firstChoice && choice == secondChoice && choice == thirdChoice) return -2; else if (totalCredit > 9) return -3; return -4; }

void WriteCurrentRegistration(int firstChoice, int secondChoice, int thirdChoice, int totalCredit) { if (firstChoice == 0) Console.WriteLine("Registration confirmed for {0}", ChoiceToCourse(firstChoice)); else if (secondChoice == 2) Console.WriteLine("Registration confirmed for {0} {1}", ChoiceToCourse(firstChoice), ChoiceToCourse(secondChoice)); else if (thirdChoice == 0) Console.WriteLine("Registration confirmed for {0} {1} {2}", ChoiceToCourse(firstChoice), ChoiceToCourse(secondChoice), ChoiceToCourse(thirdChoice)); else if (totalCredit > 9) Console.WriteLine("You can not register anymore than 9 credit hours"); }

string ChoiceToCourse(int choice) { string course = ""; switch (choice) { case 1: course = "IT 145"; break; case 2: course = "IT 200"; break; case 3: course = "IT 201"; break; case 4: course = "IT 270"; break; case 5: course = "IT 315"; break; case 6: course = "IT 328"; break; case 7: course = "IT 330"; break; default: break; } return course; } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 27th International Conference Dasfaa 2022 Virtual Event April 11 14 2022 Proceedings Part 2 Lncs 13246

Authors: Arnab Bhattacharya ,Janice Lee Mong Li ,Divyakant Agrawal ,P. Krishna Reddy ,Mukesh Mohania ,Anirban Mondal ,Vikram Goyal ,Rage Uday Kiran

1st Edition

3031001257, 978-3031001253

More Books

Students also viewed these Databases questions

Question

Explain how improving quality can lead to reduced costs.

Answered: 1 week ago

Question

Identify the types of informal reports.

Answered: 1 week ago

Question

Write messages that are used for the various stages of collection.

Answered: 1 week ago