using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Assignment_3
{
class Program
{
static void Main(string[] args)
{
char y = (char)Console.Read();
double DblA; // none members
double DblB; // none members
double DblC; // none members
double DblD; // none members
double Dbl2PersonTent = 3.00; // none members
double DblOtherTents = 5.00; // none members
double DblCaravan = 10.00; // none members
double DblChalet = 15.00; // none members
double DblMA; // Start Members
double DblMB;
double DblMC;
double DblMD;
double Dbl2PersonTentMembers = 2.25;
double DblOtherTentsMembers = 3.75;
double DblCaravanMemebers = 7.50;
double DblChaletMembers = 11.25; // End Members
double DblNightsStay;
String StrNightsStay;
char a = (char)Console.Read();
char A = (char)Console.Read();
char b = (char)Console.Read();
char B = (char)Console.Read();
char c = (char)Console.Read();
char C = (char)Console.Read();
char d = (char)Console.Read();
char D = (char)Console.Read();
DblA = Dbl2PersonTent;
DblB = DblOtherTents;
DblC = DblCaravan;
DblD = DblChalet;
StrNightsStay = Console.ReadLine();
DblNightsStay = double.Parse(StrNightsStay);
Console.WriteLine("Are you a member enter Y for yes or N for no: ");
if (char.IsLetter(y))
{
Console.Write("\nA 2 Person tent £3.00 per night");
Console.Write("\nB Other tents £5.00 per night");
Console.Write("\nC Caravan £10.00 per night");
Console.Write("\nD Chalet £15.00 per night");
Console.Write("\nMembers get a 25% Discount");
Console.ReadLine();
Console.Write("Please enter A,B,C,D for your chosen holiday type: ");
if
(Char.IsLetter(A))
{
Console.Write("how many nights would you like to stay: ");
StrNightsStay = Console.ReadLine();
DblMA = Dbl2PersonTentMembers * DblNightsStay;
Console.WriteLine("Your Cost for this holiday is £");
Console.WriteLine(DblMA);
Console.ReadLine();
}
else if
(Char.IsLetter(B))
{
Console.Write("how many nights would you like to stay: ");
StrNightsStay = Console.ReadLine();
DblMB = DblOtherTentsMembers * DblNightsStay;
Console.WriteLine("Your Cost for this holiday is £");
Console.WriteLine(DblMB);
Console.ReadLine();
}
else if
(Char.IsLetter(C))
{
Console.Write("how many nights would you like to stay: ");
StrNightsStay = Console.ReadLine();
DblMC = DblCaravanMemebers * DblNightsStay;
Console.WriteLine("Your Cost for this holiday is £");
Console.WriteLine(DblMC);
Console.ReadLine();
}
else if
(Char.IsLetter(D))
{
Console.Write("how many nights would you like to stay: ");
StrNightsStay = Console.ReadLine();
DblMD = DblChaletMembers * DblNightsStay;
Console.WriteLine("Your Cost for this holiday is £");
Console.WriteLine(DblMD);
Console.ReadLine();
}
}
else
{
Console.Write("\nA 2 Person tent £3.00 per night");
Console.Write("\nB Other tents £5.00 per night");
Console.Write("\nC Caravan £10.00 per night");
Console.Write("\nD Chalet £15.00 per night");
Console.ReadLine();
Console.Write("Please enter A,B,C,D for your chosen holiday type: ");
if
(Char.IsLetter(A))
{
Console.Write("how many nights would you like to stay: ");
StrNightsStay = Console.ReadLine();
DblA = Dbl2PersonTent * DblNightsStay;
Console.WriteLine("Your Cost for this holiday is £");
Console.WriteLine(DblA);
Console.ReadLine();
}
else if
(Char.IsLetter(B))
{
Console.Write("how many nights would you like to stay: ");
StrNightsStay = Console.ReadLine();
DblB = DblOtherTents * DblNightsStay;
Console.WriteLine("Your Cost for this holiday is £");
Console.WriteLine(DblB);
Console.ReadLine();
}
else if
(Char.IsLetter(C))
{
Console.Write("how many nights would you like to stay: ");
StrNightsStay = Console.ReadLine();
DblC = DblCaravan * DblNightsStay;
Console.WriteLine("Your Cost for this holiday is £");
Console.WriteLine(DblC);
Console.ReadLine();
}
else if
(Char.IsLetter(D))
{
Console.Write("how many nights would you like to stay: ");
StrNightsStay = Console.ReadLine();
DblD = DblChalet * DblNightsStay;
Console.WriteLine("Your Cost for this holiday is £");
Console.WriteLine(DblD);
Console.ReadLine();
}
}
}
}
}
Sam HobbsPosted Oct 12, 2010, 4:57 PM
Sam HobbsPosted Oct 12, 2010, 4:42 PM
One thing that is likely confusing is that a holiday can be the data describing the possible holidays for example the type of tent and such or it can be a specific holiday in terms of the type of holiday that was chosen and the number of days and such. All this is a good beginning at understanding Object Oriented Programming (OOP).
stephen turveyPosted Oct 12, 2010, 4:21 AM
Sam HobbsPosted Oct 12, 2010, 12:07 AM
One advantage of separating high-level from low-level is it makes your top-level logic easier to read. Experienced programmers try to separate the high-level logic from lower-level logic. You original program has all levels combined together. It is not as much of a problem in your current program but more complex requirements can quickly make the program much more cmplicated.
Another advantage of is that it is easier to combiine functions. You can pass parameters to functions thereby using a function multiple times each for a slightly different purpose.
You could create a class that represents each accomodation such as tent or room. The class would have the accomodation name and the cost. You could create an array of the accomodation objects then pass an instance of the array to a function that lists the accomodations and asks for a selection then calculates the holiday based on the selections and such. I understand that a lot of that is too advanced for you, but I hope it helps to have this to think about.
stephen turveyPosted Oct 10, 2010, 7:48 AM
From what I can see you have broken the code into two with nonemembers first followed by members.
Tell you the truth I did wonder if this can be done but didn't understand how untill now. Sam you have been great and I very much appreciate all the tution you have given me, I hope I can call on you again if I get stuck.
stephen turveyPosted Oct 10, 2010, 6:57 AM
Hope I don't fail my assignmnet for using code I haven't been tought by my tutor yet, tell you the truth Sam I don't think my tutor is teaching me fast enough. I understand that others in my class learn at different rates but I need a C# mental overload as I'm very interested in this subject.
I welcome all input, and as you are a very experienced programmer... if you tell me I'm doing something wrong and advice me to make changes I will do this.
Have a good day, going to take a look at your version now.
Sam HobbsPosted Oct 10, 2010, 5:48 AM
Note that my version does work a little differently. My version assumes that the same person is using it while it is executing. So my version asks if the person is a member and it does not ask again if the person is a membefr; it assumes that if the person is a member the first time, they are still a member and if not a member then they are not a member no matter how many holidays they ask for. Both of our versions ask for the person's name each time it calculates a holiday. If you need to allow the program to do calculations for more than one person (in other words, not the same person every time) during execution, then the program needs to be modified a little.
There are many more improvements, but I am not sure how much you would understand. It would take time to re-write the program some more but if I did that then I would also need to spend time explaining what I did. So for now at least, have a look at what I did.
Oh, and yes the goto is valid in the language but most programmers would have a strong negative reaction to it's use. There is absolutely no good book about the language that would recommend use of goto. Any book that teaches use of goto as being good would be considered by most programmers to be a bad book. Gotos were used a lot half a century ago but for the past quarter of a century they have been considered to be bad.
stephen turveyPosted Oct 10, 2010, 4:29 AM
Like I said I've only been doing this 2 weeks so I'm the nood of all noobs.
The goto statment is valid in C# see here http://msdn.microsoft.com/en-us/library/13940fs2.aspx
If you know a better way then please tell me how and I'll make the changes to the code.
Again thanks for your imput.
Sam HobbsPosted Oct 9, 2010, 8:36 PM
stephen turveyPosted Oct 9, 2010, 7:58 PM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Start:
string StrChoice = "";
string StrName;
string StrNightsStay;
double DblNightsStay;
Console.Clear();
Console.Write("\nWelcome to your holiday planner\n");
Console.Write("Member's get 25% of their holidays this year, are you a member Y/N?:");
StrChoice = Console.ReadLine();
if (StrChoice == "Y")
{
goto Members;
}
else
if (StrChoice == "N")
{
goto NoneMembers;
}
Members:
double DblMA;
double DblMB;
double DblMC;
double DblMD;
double DblM2PersonTent = 2.25;
double DblMOtherTents = 3.75;
double DblMCaravan = 7.50;
double DblMChalet = 11.25;
Console.Clear();
Console.Write("What is your full name:");
StrName = Console.ReadLine();
Console.Clear();
Console.Write("Welcome back {0}", StrName);
Console.Write("\nHere is this years holiday prices, your 25% discount will be detucted \non your final quote.\n");
Console.Write("\nA 2 person tent costs £3.00 per night\n");
Console.Write("B Other tents costs £5.00 per night\n");
Console.Write("C Caravan costs £10.00 per night\n");
Console.Write("D Chalet costs £15.00 per night\n");
Console.Write("\nPlease enter you holiday type:");
StrChoice = Console.ReadLine();
if (StrChoice == "A")
{
Console.Write("\nHow many nights would you like to stay with us:");
StrNightsStay = Console.ReadLine();
DblNightsStay = double.Parse(StrNightsStay);
DblMA = DblM2PersonTent * DblNightsStay;
Console.Write(" \nYour cost of this holiday is:{0}", DblMA);
Console.Write(" \nWould you like to try a different choice of holiday Y/N:");
StrChoice = Console.ReadLine();
if (StrChoice == "Y")
{
goto Start;
}
else
{
}
}
else
if (StrChoice == "B")
{
Console.Write("\nHow many nights would you like to stay with us:\n");
StrNightsStay = Console.ReadLine();
DblNightsStay = double.Parse(StrNightsStay);
DblMB = DblMOtherTents * DblNightsStay;
Console.Write(" \nYour cost of this holiday is:{0}", DblMB);
Console.Write(" \nWould you like to try a different choice of holiday Y/N:");
StrChoice = Console.ReadLine();
if (StrChoice == "Y")
{
goto Start;
}
else
{
}
}
else
if (StrChoice == "C")
{
Console.Write("\nHow many nights would you like to stay with us:\n");
StrNightsStay = Console.ReadLine();
DblNightsStay = double.Parse(StrNightsStay);
DblMC = DblMCaravan * DblNightsStay;
Console.Write(" \nYour cost of this holiday is:{0}", DblMC);
Console.Write(" \nWould you like to try a different choice of holiday Y/N:");
StrChoice = Console.ReadLine();
if (StrChoice == "Y")
{
goto Start;
}
else
{
}
}
else
if (StrChoice == "D")
{
Console.Write("How many nights would you like to stay with us:");
StrNightsStay = Console.ReadLine();
DblNightsStay = double.Parse(StrNightsStay);
DblMD = DblMChalet * DblNightsStay;
Console.Write(" \nYour cost of this holiday is:{0}", DblMD);
Console.Write(" \nWould you like to try a different choice of holiday Y/N:");
StrChoice = Console.ReadLine();
if (StrChoice == "Y")
{
goto Start;
}
else
{
}
}
else
if (StrChoice == "N")
{
goto NoneMembers;
}
NoneMembers:
double DblA;
double DblB;
double DblC;
double DblD;
double Dbl2PersonTent = 3.00;
double DblOtherTents = 5.00;
double DblCaravan = 10.00;
double DblChalet = 15.00;
Console.Clear();
Console.Write("What is your full name:");
StrName = Console.ReadLine();
Console.Clear();
Console.Write("Welcome back {0}", StrName);
Console.Write("\nHere is this years holiday prices, if you was a member you would of saved 25%\non your holiday.\n");
Console.Write("\nA 2 person tent costs £3.00 per night\n");
Console.Write("B Other tents costs £5.00 per night\n");
Console.Write("C Caravan costs £10.00 per night\n");
Console.Write("D Chalet costs £15.00 per night\n");
Console.Write("\nPlease enter you holiday type:");
StrChoice = Console.ReadLine();
if (StrChoice == "A")
{
Console.Write("\nHow many nights would you like to stay with us:");
StrNightsStay = Console.ReadLine();
DblNightsStay = double.Parse(StrNightsStay);
DblA = Dbl2PersonTent * DblNightsStay;
Console.Write(" \nYour cost of this holiday is:{0}", DblA);
Console.Write(" \nWould you like to try a different choice of holiday Y/N:");
StrChoice = Console.ReadLine();
if (StrChoice == "Y")
{
goto Start;
}
else
{
}
}
else
if (StrChoice == "B")
{
Console.Write("\nHow many nights would you like to stay with us:\n");
StrNightsStay = Console.ReadLine();
DblNightsStay = double.Parse(StrNightsStay);
DblB = DblOtherTents * DblNightsStay;
Console.Write(" \nYour cost of this holiday is:{0}", DblB);
Console.Write(" \nWould you like to try a different choice of holiday Y/N:");
StrChoice = Console.ReadLine();
if (StrChoice == "Y")
{
goto Start;
}
else
{
}
}
else
if (StrChoice == "C")
{
Console.Write("\nHow many nights would you like to stay with us:\n");
StrNightsStay = Console.ReadLine();
DblNightsStay = double.Parse(StrNightsStay);
DblC = DblCaravan * DblNightsStay;
Console.Write(" \nYour cost of this holiday is:{0}", DblC);
Console.Write(" \nWould you like to try a different choice of holiday Y/N:");
StrChoice = Console.ReadLine();
if (StrChoice == "Y")
{
goto Start;
}
else
{
}
}
else
if (StrChoice == "D")
{
Console.Write("How many nights would you like to stay with us:");
StrNightsStay = Console.ReadLine();
DblNightsStay = double.Parse(StrNightsStay);
DblD = DblChalet * DblNightsStay;
Console.Write(" \nYour cost of this holiday is:{0}", DblD);
Console.Write(" \nWould you like to try a different choice of holiday Y/N:");
StrChoice = Console.ReadLine();
if (StrChoice == "Y")
{
goto Start;
}
else
{
}
}
else
if (StrChoice == "N")
{
}
}
}
}
stephen turveyPosted Oct 8, 2010, 6:16 PM
Thanks for you help.
Sam HobbsPosted Oct 8, 2010, 4:59 PM
I suggest making functions for doing things so that your main function is smaller. If you don't understand what I mean then ignore it.
One big problem is that you are writing "Your Cost for this holiday is £" but you are not writing the cost. You need to refer to your notes from class or something such as that to know how to write the cost; it will be something such as:
You say you get a "blanks screen". I suspect that the screen is not totally blank; I suspectg that you are getting something but just not everything. If so then you need to learn to be accurate in your problem description. There is no evidence that the program won't show something at least so people have not been able to help you with that. If instead you are getting some output but not all and if you had said that that is what is happening then you would have gotten more help sooner.
Jean PaulPosted Oct 8, 2010, 6:06 AM
I found the following error:
The Console.Read() goes for an infinite loop reading char.
Instead of that use
char y = (char)Console.ReadKey().KeyChar;
for all the Read()
Whenever you are using ReadLine() use enter charcter to complete the reading.
Happy Coding Dude!