C# help?
-
Thank you so much for your help. Now it is giving me new errors for something else and I dont understand. Does anyone know?
public static void Main()
{
stringinput,firstname,lastname;
double idium;
int password, choice;
string name;Console.WriteLine("Enter your firstname:"); Console.WriteLine("Enter your ID Number:"); input = Console.ReadLine(); FirstName = Convert.ToString(input); Console.WriteLine("Enter your lastname:"); input = Console.ReadLine(); LastName = Convert.ToString(input);
}
public static void checkout()
{Console.Write("You are ready to check out."); double\[\] payRate; payRate = new double\[4\]; payRate\[0\] = 3.00; payRate\[1\] = 4.15; payRate\[2\] = 6.42; payRate\[3\] = 7.95; for(int x = 0; x < 4; ++x) Console.WriteLine("Pay rate {0} is {1}", x, payRate\[x\].ToString("C"));
}
}
-
Thank you so much for your help. Now it is giving me new errors for something else and I dont understand. Does anyone know?
public static void Main()
{
stringinput,firstname,lastname;
double idium;
int password, choice;
string name;Console.WriteLine("Enter your firstname:"); Console.WriteLine("Enter your ID Number:"); input = Console.ReadLine(); FirstName = Convert.ToString(input); Console.WriteLine("Enter your lastname:"); input = Console.ReadLine(); LastName = Convert.ToString(input);
}
public static void checkout()
{Console.Write("You are ready to check out."); double\[\] payRate; payRate = new double\[4\]; payRate\[0\] = 3.00; payRate\[1\] = 4.15; payRate\[2\] = 6.42; payRate\[3\] = 7.95; for(int x = 0; x < 4; ++x) Console.WriteLine("Pay rate {0} is {1}", x, payRate\[x\].ToString("C"));
}
}
I will agree with Pete in your last posting - "This is fairly basic stuff". Perhaps you could look into a few online tutorials? That would probably help you to learn this better than asking several questions here. Rather than trying to make a given block of code work, I would advise to learn the fundamentals instead...
-
Thank you so much for your help. Now it is giving me new errors for something else and I dont understand. Does anyone know?
public static void Main()
{
stringinput,firstname,lastname;
double idium;
int password, choice;
string name;Console.WriteLine("Enter your firstname:"); Console.WriteLine("Enter your ID Number:"); input = Console.ReadLine(); FirstName = Convert.ToString(input); Console.WriteLine("Enter your lastname:"); input = Console.ReadLine(); LastName = Convert.ToString(input);
}
public static void checkout()
{Console.Write("You are ready to check out."); double\[\] payRate; payRate = new double\[4\]; payRate\[0\] = 3.00; payRate\[1\] = 4.15; payRate\[2\] = 6.42; payRate\[3\] = 7.95; for(int x = 0; x < 4; ++x) Console.WriteLine("Pay rate {0} is {1}", x, payRate\[x\].ToString("C"));
}
}
Apart from the errors (tip: C# is case-sensitive), what's up with this?
Brian Reiber wrote:
input = Console.ReadLine(); LastName = Convert.ToString(input);
It's already string, why convert a string to a string? ILSpy confirms that the overload of Convert.ToString that takes a string argument just returns that string:
public static string ToString(string value)
{
return value;
} -
Thank you so much for your help. Now it is giving me new errors for something else and I dont understand. Does anyone know?
public static void Main()
{
stringinput,firstname,lastname;
double idium;
int password, choice;
string name;Console.WriteLine("Enter your firstname:"); Console.WriteLine("Enter your ID Number:"); input = Console.ReadLine(); FirstName = Convert.ToString(input); Console.WriteLine("Enter your lastname:"); input = Console.ReadLine(); LastName = Convert.ToString(input);
}
public static void checkout()
{Console.Write("You are ready to check out."); double\[\] payRate; payRate = new double\[4\]; payRate\[0\] = 3.00; payRate\[1\] = 4.15; payRate\[2\] = 6.42; payRate\[3\] = 7.95; for(int x = 0; x < 4; ++x) Console.WriteLine("Pay rate {0} is {1}", x, payRate\[x\].ToString("C"));
}
}
Something else that you have failed to do is to show the actual error message that you receive. Don't expect others to be able to see what's happening on your PC when you try compiling this.
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
Thank you so much for your help. Now it is giving me new errors for something else and I dont understand. Does anyone know?
public static void Main()
{
stringinput,firstname,lastname;
double idium;
int password, choice;
string name;Console.WriteLine("Enter your firstname:"); Console.WriteLine("Enter your ID Number:"); input = Console.ReadLine(); FirstName = Convert.ToString(input); Console.WriteLine("Enter your lastname:"); input = Console.ReadLine(); LastName = Convert.ToString(input);
}
public static void checkout()
{Console.Write("You are ready to check out."); double\[\] payRate; payRate = new double\[4\]; payRate\[0\] = 3.00; payRate\[1\] = 4.15; payRate\[2\] = 6.42; payRate\[3\] = 7.95; for(int x = 0; x < 4; ++x) Console.WriteLine("Pay rate {0} is {1}", x, payRate\[x\].ToString("C"));
}
}
What errors are you getting?
Brian Reiber wrote:
stringinput
I suspect you mean
string input
Brian Reiber wrote:
input = Console.ReadLine(); FirstName = Convert.ToString(input);
Why not simply
FirstName = Console.ReadLine();
?Brian Reiber wrote:
Convert
I recommend never using Convert other than Convert.ChangeType
Brian Reiber wrote:
{1} ... , payRate[x].ToString("C")
Try using
{1:C}
instead of the ToString. -
Thank you so much for your help. Now it is giving me new errors for something else and I dont understand. Does anyone know?
public static void Main()
{
stringinput,firstname,lastname;
double idium;
int password, choice;
string name;Console.WriteLine("Enter your firstname:"); Console.WriteLine("Enter your ID Number:"); input = Console.ReadLine(); FirstName = Convert.ToString(input); Console.WriteLine("Enter your lastname:"); input = Console.ReadLine(); LastName = Convert.ToString(input);
}
public static void checkout()
{Console.Write("You are ready to check out."); double\[\] payRate; payRate = new double\[4\]; payRate\[0\] = 3.00; payRate\[1\] = 4.15; payRate\[2\] = 6.42; payRate\[3\] = 7.95; for(int x = 0; x < 4; ++x) Console.WriteLine("Pay rate {0} is {1}", x, payRate\[x\].ToString("C"));
}
}
Brian: I am going to echo the recommendations of another post. As a new (and I really cannot refer to myself as a developer, yet) I researched online tutorials and books that would provide a foundation for C#, and VS 2010. The following books have proven to be valuable resources: 1. Beginning C# Object Oriented Programming by Dan Clark (READ Chapter 5) 2. Visual C# 2010 Recipes by Jones and Freeman 3. HeadFirst C# by Stellman and Greene 4. Programming Language Pragmatics by Scott (buy it and put in on the bookshelf for a goal in understanding). It's beyond new developers, but it's a good feeling to go to the book and "get it" after study. 5. Herding Cats - A Primer for Programmers Who Lead Programmers by Rainwater (this book helps me understand those in the world of programming, as I come from the academic "world"). 6. Online tutorials available from Lynda.com My mentor (who has been programming since God was a child) says "Work on your errors for 2 hours, THEN ask for help". My greatest hurdle has been in understanding the vocabulary that is used, and I finally had to stop obsessing... It is what it is. Oh...Petzold's free online book (263 pages)was recommmended to me(Richard?), and is proving to be interesting, but I don't do well with books I cannot markup with pencil notations. Two other books have been recommended, but they are on my Amazon wish list. Code Complete, and New Programmer's Survival Manual. Looking at your code (I c/p'd into VS, and messed around with it), I was able to reduce the errors to 3, but then was stumped by my own ignorance...and I am not cheeky enough to make suggestions for changes. So your code helped me learn, so thank you. Best of luck.
-
Thank you so much for your help. Now it is giving me new errors for something else and I dont understand. Does anyone know?
public static void Main()
{
stringinput,firstname,lastname;
double idium;
int password, choice;
string name;Console.WriteLine("Enter your firstname:"); Console.WriteLine("Enter your ID Number:"); input = Console.ReadLine(); FirstName = Convert.ToString(input); Console.WriteLine("Enter your lastname:"); input = Console.ReadLine(); LastName = Convert.ToString(input);
}
public static void checkout()
{Console.Write("You are ready to check out."); double\[\] payRate; payRate = new double\[4\]; payRate\[0\] = 3.00; payRate\[1\] = 4.15; payRate\[2\] = 6.42; payRate\[3\] = 7.95; for(int x = 0; x < 4; ++x) Console.WriteLine("Pay rate {0} is {1}", x, payRate\[x\].ToString("C"));
}
}
Please give your questions a meaningful subject. Every question posted in this forum is from someone looking for 'C# Help'. If you are getting error messages, first of all examine them and they will normally give you enough information to fix them! I recommend turning on line numbers in Visual Studio if you haven't already: Tools|Option|Editor|C# and check the Line numbers box. Secondly, use a search engine of your choice and search for the error message (excluding any parts specific to your project). Thirdly, if you still need help, post the error message here and indicate on which line of your code posted it actually fails on. These will save people who wish to help you a lot of time and will make it far more probable that you will get a helpful answer.
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
Thank you so much for your help. Now it is giving me new errors for something else and I dont understand. Does anyone know?
public static void Main()
{
stringinput,firstname,lastname;
double idium;
int password, choice;
string name;Console.WriteLine("Enter your firstname:"); Console.WriteLine("Enter your ID Number:"); input = Console.ReadLine(); FirstName = Convert.ToString(input); Console.WriteLine("Enter your lastname:"); input = Console.ReadLine(); LastName = Convert.ToString(input);
}
public static void checkout()
{Console.Write("You are ready to check out."); double\[\] payRate; payRate = new double\[4\]; payRate\[0\] = 3.00; payRate\[1\] = 4.15; payRate\[2\] = 6.42; payRate\[3\] = 7.95; for(int x = 0; x < 4; ++x) Console.WriteLine("Pay rate {0} is {1}", x, payRate\[x\].ToString("C"));
}
}
-
Thank you so much for your help. Now it is giving me new errors for something else and I dont understand. Does anyone know?
public static void Main()
{
stringinput,firstname,lastname;
double idium;
int password, choice;
string name;Console.WriteLine("Enter your firstname:"); Console.WriteLine("Enter your ID Number:"); input = Console.ReadLine(); FirstName = Convert.ToString(input); Console.WriteLine("Enter your lastname:"); input = Console.ReadLine(); LastName = Convert.ToString(input);
}
public static void checkout()
{Console.Write("You are ready to check out."); double\[\] payRate; payRate = new double\[4\]; payRate\[0\] = 3.00; payRate\[1\] = 4.15; payRate\[2\] = 6.42; payRate\[3\] = 7.95; for(int x = 0; x < 4; ++x) Console.WriteLine("Pay rate {0} is {1}", x, payRate\[x\].ToString("C"));
}
}
OK, you've had a bit of time to fix your errors and enough hints... Here is working code with a) reduntant items removed b) code styling and variable/method names changed where appropriate c) other suggestions applied d) the double array moved outside of the method - unless it's going to be different every time (as it's hardcoded I assume not) then it makes no sense to keep it there Study it and the differences and see if you can learn from it:
private static readonly double\[\] PayRate = new double\[4\] { 3.00, 4.15, 6.42, 7.95 }; static void Main() { Console.WriteLine("Enter your forename:"); string forename = Console.ReadLine(); Console.WriteLine("Enter your surname:"); string surname = Console.ReadLine(); Checkout(); Console.ReadKey(); } private static void Checkout() { Console.WriteLine("You are ready to check out."); for (int i = 0; i < PayRate.Length; i++) Console.WriteLine("Pay rate {0} is {1:C}", i, PayRate\[i\]); }
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
Please give your questions a meaningful subject. Every question posted in this forum is from someone looking for 'C# Help'. If you are getting error messages, first of all examine them and they will normally give you enough information to fix them! I recommend turning on line numbers in Visual Studio if you haven't already: Tools|Option|Editor|C# and check the Line numbers box. Secondly, use a search engine of your choice and search for the error message (excluding any parts specific to your project). Thirdly, if you still need help, post the error message here and indicate on which line of your code posted it actually fails on. These will save people who wish to help you a lot of time and will make it far more probable that you will get a helpful answer.
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn):thumbsup:
Luc Pattyn [My Articles] Nil Volentibus Arduum
-
Brian: I am going to echo the recommendations of another post. As a new (and I really cannot refer to myself as a developer, yet) I researched online tutorials and books that would provide a foundation for C#, and VS 2010. The following books have proven to be valuable resources: 1. Beginning C# Object Oriented Programming by Dan Clark (READ Chapter 5) 2. Visual C# 2010 Recipes by Jones and Freeman 3. HeadFirst C# by Stellman and Greene 4. Programming Language Pragmatics by Scott (buy it and put in on the bookshelf for a goal in understanding). It's beyond new developers, but it's a good feeling to go to the book and "get it" after study. 5. Herding Cats - A Primer for Programmers Who Lead Programmers by Rainwater (this book helps me understand those in the world of programming, as I come from the academic "world"). 6. Online tutorials available from Lynda.com My mentor (who has been programming since God was a child) says "Work on your errors for 2 hours, THEN ask for help". My greatest hurdle has been in understanding the vocabulary that is used, and I finally had to stop obsessing... It is what it is. Oh...Petzold's free online book (263 pages)was recommmended to me(Richard?), and is proving to be interesting, but I don't do well with books I cannot markup with pencil notations. Two other books have been recommended, but they are on my Amazon wish list. Code Complete, and New Programmer's Survival Manual. Looking at your code (I c/p'd into VS, and messed around with it), I was able to reduce the errors to 3, but then was stumped by my own ignorance...and I am not cheeky enough to make suggestions for changes. So your code helped me learn, so thank you. Best of luck.
Deborah Palmer McCain wrote:
I don't do well with books I cannot markup with pencil notations.
You can always print all or part of a PDF.
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
Deborah Palmer McCain wrote:
I don't do well with books I cannot markup with pencil notations.
You can always print all or part of a PDF.
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
Yes, I read through part the book, and will be printing it so I can mark it. Truly a valuable resource, thank you again. Deborah