Hey, all I am currently doing an assignment and I am having a tough time with managing my output. What I am trying to do is that when the program ends it asks the user if they would want to try again if yes it loops back to the beginning if no it exits. So my problem here is whenever I loop back to the beginning the output gets destroyed. I am a beginner programmer, and it is just now I've tried C# (I came from C++). I think the problem is coming from my console.writeline(), I think it leaves a phantom character(? not sure) like in c++'s getline(). The following snippets are my main class and the abstract data type that I created.
//THIS IS MY MAIN
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FeeComputation_Adina
{
class FeeComputation
{
static void Main(string[] args)
{
string nameFirst, nameLast, course;
char gender, nameMI, doReload;
int year, unitsLec, unitsLab;
bool isGenderInCorrect = true, isInCorrectLoad = true, isYLVLInCorrect = true, isInCorrectChoice = true, isReload = true;
callIntroMessage();
do
{
callTitle();
callStudentInfoHeader();
Console.Write("\t\t\tEnter Last Name: "); nameLast = Convert.ToString(Console.ReadLine());
Console.Write("\t\t\tEnter First Name: "); nameFirst = Convert.ToString(Console.ReadLine());
Console.Write("\t\t\tEnter Middle Initial: "); nameMI = Convert.ToChar(Console.ReadLine());
do
{
Console.Write("\t\t\tEnter Gender [M/F]: "); gender = Convert.ToChar(Console.ReadLine());
if ((gender == 'm') || (gender == 'M') || (gender == 'F') || (gender == 'f'))
{
isGenderInCorrect = false;
}
else
{
Console.Clear();
Console.WriteLine("You have input an incorrect gender.");
Console.WriteLine("Correct choices are: 'F' for female and 'M' for male, please try again.");
Console.Write("Press any key to continue . . .");
Console.ReadKey(); Console.Clear();
isGenderInCorrect = true;
}
callTitle();
callStudentInfoHeader();
Console.WriteLine("\t\t\tEnter Last Name: " + nameLast);
Console.WriteLine("\t\t\tEnter First Name: " + nameFirst);
Console.WriteLine("\t\t\tEnter Middle Initial: " + nameMI);
}
while (isGenderInCorrect);
Console.Clear();
callTitle();
callDegreeYearHeader();
Console.Write("\t\t\tEnter Degree Program: "); course = Convert.ToString(Console.ReadLine());
do
{
Console.Write("\t\t\tEnter Current Year Level: "); year = Convert.ToInt32(Console.ReadLine());
if ((year < 1) || (year > 5))
{
Console.Clear();
Console.WriteLine("You have input an incorrect year level.");
Console.WriteLine("Year level ranges only from 1 to 5, please try again.");
Console.Write("Press any key to continue . . .");
Console.ReadKey(); Console.Clear();
isYLVLInCorrect = true;
}
else if ((year >= 1) && (year <= 5))
{
isYLVLInCorrect = false;
}
callTitle();
callDegreeYearHeader();
Console.WriteLine("\t\t\tEnter Degree Program: " + course);
}
while (isYLVLInCorrect);
Console.Clear();
do
{
callTitle();
callLabLecUnitHeader();
Console.Write("\t\t Enter Currently Enrolled Lecture Units: "); unitsLec = Convert.ToInt32(Console.ReadLine());
Console.Write("\t\t Enter Currently Enrolled Laboratory Units: "); unitsLab = Convert.ToInt32(Console.ReadLine());
if ((unitsLec + unitsLab) < 12)
{
Console.Clear();
Console.WriteLine("You have made an error.");
Console.WriteLine("The total number of units inccured is only " + (unitsLec + unitsLab) + (" unit(s)."));
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("This means the student is UNDERLOADED.");
Console.WriteLine("Please input the correct number of units to fix this problem.");
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("Please note that the MINIMUM number of units allowed is only 12.");
Console.WriteLine(); Console.WriteLine();
Console.Write("Press any key to continue . . .");
Console.ReadKey(); Console.Clear();
isInCorrectLoad = true;
}
else if ((unitsLec + unitsLab) > 18)
{
Console.Clear();
Console.WriteLine("You have made an error.");
Console.WriteLine("The total number of units inccured is " + (unitsLec + unitsLab) + (" units."));
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("This means the student is OVERLOADED.");
Console.WriteLine("Please input the correct number of units to fix this problem.");
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("Please note that the MAXIMUM number of units allowed is only 18.");
Console.WriteLine(); Console.WriteLine();
Console.Write("Press any key to continue . . .");
Console.ReadKey(); Console.Clear();
isInCorrectLoad = true;
}
else if (((unitsLec + unitsLab) <= 18) && ((unitsLec + unitsLab) >= 12))
{
isInCorrectLoad = false;
}
}
while (isInCorrectLoad);
Console.Clear();
StudentTuitionFee studentInfo = new StudentTuitionFee(nameFirst, nameMI, nameLast, gender, course, year);
displayBreakDown(studentInfo, unitsLec, unitsLab, gender, nameFirst, nameMI, nameLast, course, year);
Console.Clear();
Console.Write("Would you like to compute the tuition fee for a different student? [Y/N]: "); //TRY MAKING THIS A COMMENT AND IT WILL RUN SMOOTHLY
doReload = Convert.ToChar(Console.Read());
Console.Write("Press any key to continue . . .");
Console.ReadKey();
Console.Clear();
do
{
if ((doReload == 'y') || (doReload == 'Y'))
{
isInCorrectChoice = false;
isReload = true;
}
else if ((doReload == 'n') || (doReload == 'N'))
{
isInCorrectChoice = false;
isReload = false;
Console.WriteLine(); Console.WriteLine();
Console.Write("Press any key to continue . . .");
Console.ReadKey();
}
else if ((doReload == 'y') || (doReload == 'Y') || (doReload != 'n') || (doReload != 'N'))
{
Console.Clear();
Console.WriteLine("You have input an incorrect choice.");
Console.WriteLine("Answer choices are only 'Y' for yes and 'N' for no, please try again.");
Console.WriteLine("Press any key to continue . . .");
Console.ReadKey(); Console.Clear();
isInCorrectChoice = true;
isReload = true;
}
}
while (isInCorrectChoice);
}
while (isReload);
}
static void callTitle()
{
Console.WriteLine(" xXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXx");
Console.WriteLine("x x");
Console.WriteLine("X X");
Console.WriteLine("x Basic Tuition Fee Calculator v1.00 x");
Console.WriteLine("X X");
Console.WriteLine("x x");
Console.WriteLine(" xXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXx");
Console.WriteLine(); Console.WriteLine();
}
static void callStudentInfoHeader()
{
Console.WriteLine(" oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo");
Console.WriteLine("O O");
Console.WriteLine("o o");
Console.WriteLine("O Student Name and Gender O");
Console.WriteLine("o o");
Console.WriteLine("O O");
Console.WriteLine(" oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo");
Console.WriteLine(); Console.WriteLine();
}
static void callDegreeYearHeader()
{
Console.WriteLine(" oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo");
Console.WriteLine("O O");
Console.WriteLine("o o");
Console.WriteLine("O Degree and Year Level O");
Console.WriteLine("o o");
Console.WriteLine("O O");
Console.WriteLine(" oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo");
Console.WriteLine(); Console.WriteLine();
}
static void callLabLecUnitHeader()
{
Console.WriteLine(" oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo");
Console.WriteLine("O O");
Console.WriteLine("o o");
Console.WriteLine("O Laboratory and Lecture Units Enrolled O");
Console.WriteLine("o o");
Console.WriteLine("O O");
Console.WriteLine(" oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo");
Console.WriteLine(); Console.WriteLine();
}
static void callIntroMessage()
{
callTitle();
Console.WriteLine(" xXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXx");
Console.WriteLine("x x");
Console.WriteLine("X Welcome! This is a simple tuition fee calculator that will X");
Console.WriteLine("x accept proper input from the user and compute for the tui- x");
Console.WriteLine("X tion fee of a student with respect to their gender and out- X");
Console.WriteLine("x put a properly tabulated matriculation of fees. x");
Console.WriteLine("x x");
Console.WriteLine("x Press any key to continue! x");
Console.WriteLine("x x");
Console.WriteLine(" xXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXx");
Console.ReadKey(); Console.Clear();
}
static void displayBreakDown(StudentTuitionFee studentInfo, int unitsLec, int unitsLab, char gender, string nameFirst, char nameMI, string nameLast, string course, int year)
{
callTitle();
Console.WriteLine();
Console.WriteLine(studentInfo.getLectureUnitFee(unitsLec));
Console.WriteLine(studentInfo.getLabUnitFee(unitsLab));
Console.WriteLine(studentInfo.getTotalUnitFee(unitsLec, unitsLab));
Console.WriteLine(studentInfo.getTotalTuitionFee(unitsLec, unitsLab, gender));
Console.WriteLine(studentInfo.getTotalMiscFee(gender));
Console.WriteLine(nameFirst + nameMI + nameLast + gender);
Console.WriteLine(course + year);
Console.WriteLine(unitsLab + unitsLec);
Console.WriteLine(); Console.WriteLine();
Console.Write("Press any key to continue . . .");
Console.ReadKey();
}
}
}
//THIS IS MY ABSTRACT DATA TYPE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FeeComputation_Adina
{
class StudentTuitionFee
{
const double feeINTER = 2500.00, feeID = 150.00, feeSCDL = 100.00, feeHBOOK = 230.00, feeROTC = 1500.00, perUnitFee = 748.00;
string studentFirstName, studentLastName, studentCourse;
char studentMI, studentGender;
int studentCourseYear;
public StudentTuitionFee(string FN, char MI, string LN, char gender, string course, int yearLevel)
{
studentFirstName = FN;
studentMI = MI;
studentLastName = LN;
studentGender = gender;
studentCourse = course;
studentCourseYear = yearLevel;
}
public double getLectureUnitFee(int unitsLecture)
{
return perUnitFee * unitsLecture;
}
public double getLabUnitFee(int unitsLaboratory)
{
return perUnitFee * unitsLaboratory;
}
public double getTotalUnitFee(int unitsLecture, int unitsLaboratory)
{
return ((unitsLecture + unitsLaboratory) * perUnitFee);
}
public double getTotalTuitionFee(int unitsLecture, int unitsLaboratory, char studGender)
{
if ((studGender == 'm') || (studGender == 'M'))
{
return (feeINTER + feeID + feeROTC + feeSCDL + ((unitsLaboratory + unitsLecture) * perUnitFee));
}
else if ((studGender == 'f') || (studGender == 'F'))
{
return (feeINTER + feeID + feeSCDL + ((unitsLaboratory + unitsLecture) * perUnitFee));
}
else
{
return 0;
}
}
public double getTotalMiscFee(char studGender)
{
if ((studGender == 'm') || (studGender == 'M'))
{
return (feeINTER + feeID + feeROTC + feeSCDL);
}
else if ((studGender == 'f') || (studGender == 'F'))
{
return (feeINTER + feeID + feeSCDL);
}
else
{
return 0;
}
}
}
}
I have not implemented any data hiding for my professor told us not to do so yet. I also asked him if I should create a destructor and he just said that garbage collector should do the job for me, but my problem is when I loop I THINK I can't rely with garbage collector.
Also, what is better parse or convert.to? I find them the same but some of my peers say parse is better than convert.to because it has exception handling (but, as I have read convert.to also has that).
Thanks to those who'll be reading this and replying! Thank you so much!