471,334 Members | 1,434 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,334 software developers and data experts.

I am a new C# Programmer

Hi Guys,

I had posted awhile back that I am a new C# programmer and I have just completed my first program. It's pretty simple, but I'm having a slight problem with it. The program that I made rearranges the order of a persons name after they input it into the console. But for some reason the order of rearrangement that I set does not work the way that I want it to work. If you guys can solve my problem and tell me what I did wrong or did not do, it will be greatly appreciated. Here is my code:

using System;

namespace Name_Rearrange

{

/// <summary>

/// Name Rearranger

/// Program rearranges a persons name

/// Eric Anderson, 11.29.05

/// </summary>

class rearrange

{

static void Main(string[] args)

{

string firstname;

string middlename;

string lastname;

Console.WriteLine("Welcome to the Name Rearranger");

// Add 1 line of space here

Console.WriteLine();

Console.Write("What is your first name? ");

firstname = Console.ReadLine();

Console.Write("What is your middle name? ");

middlename = Console.ReadLine();

Console.Write("What is your last name? ");

lastname = Console.ReadLine();

// Add 1 line of space here

Console.WriteLine();

// Show rearranged name here

Console.WriteLine("{0}, {1}, {2}",firstname,middlename,lastname);

Console.WriteLine("{2}, {0}, {1}",lastname,firstname,middlename);

Console.WriteLine("{2}, {1}, {0}", lastname, middlename, firstname);
// Add 1 line of space here

Console.WriteLine();

// Ask to press enter to end

Console.WriteLine("Thank you for playing");

Console.Write("Please press the enter key to exit!");

Console.ReadLine();

}// End Main

}// End Class

}// End Namespace
--
Eric Anderson
Nov 29 '05 #1
5 1813
Eric, you need to tell us what you want it to do.

Tom Dacon
Dacon Software Consulting

"Eric Anderson" <ti*********@email.uophx.edu> wrote in message
news:O1**************@TK2MSFTNGP11.phx.gbl...
Hi Guys,

I had posted awhile back that I am a new C# programmer and I have just
completed my first program. It's pretty simple, but I'm having a slight
problem with it. The program that I made rearranges the order of a persons
name after they input it into the console. But for some reason the order of
rearrangement that I set does not work the way that I want it to work. If
you guys can solve my problem and tell me what I did wrong or did not do, it
will be greatly appreciated. Here is my code:

using System;

namespace Name_Rearrange

{

/// <summary>

/// Name Rearranger

/// Program rearranges a persons name

/// Eric Anderson, 11.29.05

/// </summary>

class rearrange

{

static void Main(string[] args)

{

string firstname;

string middlename;

string lastname;

Console.WriteLine("Welcome to the Name Rearranger");

// Add 1 line of space here

Console.WriteLine();

Console.Write("What is your first name? ");

firstname = Console.ReadLine();

Console.Write("What is your middle name? ");

middlename = Console.ReadLine();

Console.Write("What is your last name? ");

lastname = Console.ReadLine();

// Add 1 line of space here

Console.WriteLine();

// Show rearranged name here

Console.WriteLine("{0}, {1},
{2}",firstname,middlename,lastname);

Console.WriteLine("{2}, {0},
{1}",lastname,firstname,middlename);

Console.WriteLine("{2}, {1}, {0}", lastname, middlename,
firstname);
// Add 1 line of space here

Console.WriteLine();

// Ask to press enter to end

Console.WriteLine("Thank you for playing");

Console.Write("Please press the enter key to exit!");

Console.ReadLine();

}// End Main

}// End Class

}// End Namespace
--
Eric Anderson
Nov 29 '05 #2
SP
"Eric Anderson" <ti*********@email.uophx.edu> wrote in message news:O1**************@TK2MSFTNGP11.phx.gbl...
Hi Guys,

I had posted awhile back that I am a new C# programmer and I have just completed my first program. It's pretty simple, but I'm having a slight problem with it. The program that I made rearranges the order of a persons name after they input it into the console. But for some reason the order of rearrangement that I set does not work the way that I want it to work. If you guys can solve my problem and tell me what I did wrong or did not do, it will be greatly appreciated. Here is my code:

Console.WriteLine("{0}, {1}, {2}",firstname,middlename,lastname);

Console.WriteLine("{2}, {0}, {1}",lastname,firstname,middlename);

Console.WriteLine("{2}, {1}, {0}", lastname, middlename, firstname);
You should be changing only the order of the {0}, {1}, {2} and leave firstname,middlename,lastname the same.

SP

Nov 29 '05 #3

I think you might want this:

// Show rearranged name here
Console.WriteLine("{0}, {1}, {2}", firstname, middlename, lastname);
Console.WriteLine("{0}, {1}, {2}", lastname, firstname, middlename);
Console.WriteLine("{0}, {1}, {2}", lastname, middlename, firstname);
The {0} refers to the first argument. So when it prints, it will
replace {0} with the value of the first argument.

So, if you have Console.WriteLine("{1}", a, b); then the value of b
will be printed, and a will be ignored!

Another way to do your rearranging would be:

Console.WriteLine("{0}, {1}, {2}", firstname, middlename, lastname);
Console.WriteLine("{2}, {0}, {1}", firstname, middlename, lastname);
Console.WriteLine("{2}, {1}, {0}", firstname, middlename, lastname);

That is the same as the first method.
Eric Anderson wrote:
Hi Guys,

I had posted awhile back that I am a new C# programmer and I have just
completed my first program. It's pretty simple, but I'm having a slight
problem with it. The program that I made rearranges the order of a
persons name after they input it into the console. But for some reason
the order of rearrangement that I set does not work the way that I want
it to work. If you guys can solve my problem and tell me what I did
wrong or did not do, it will be greatly appreciated. Here is my code:
using System;

namespace Name_Rearrange

{

/// <summary>

/// Name Rearranger

/// Program rearranges a persons name

/// Eric Anderson, 11.29.05

/// </summary>

class rearrange

{

static void Main(string[] args)

{

string firstname;

string middlename;

string lastname;

Console.WriteLine("Welcome to the Name Rearranger");

// Add 1 line of space here

Console.WriteLine();

Console.Write("What is your first name? ");

firstname = Console.ReadLine();

Console.Write("What is your middle name? ");

middlename = Console.ReadLine();

Console.Write("What is your last name? ");

lastname = Console.ReadLine();

// Add 1 line of space here

Console.WriteLine();

// Show rearranged name here

Console.WriteLine("{0}, {1},
{2}",firstname,middlename,lastname);

Console.WriteLine("{2}, {0},
{1}",lastname,firstname,middlename);

Console.WriteLine("{2}, {1}, {0}", lastname, middlename,
firstname);

// Add 1 line of space here

Console.WriteLine();

// Ask to press enter to end

Console.WriteLine("Thank you for playing");

Console.Write("Please press the enter key to exit!");

Console.ReadLine();

}// End Main

}// End Class

}// End Namespace
--
Eric Anderson

Nov 29 '05 #4

Console.WriteLine("{0}, {1},
{2}",firstname,middlename,lastname);

Console.WriteLine("{2}, {0},
{1}",lastname,firstname,middlename);

Console.WriteLine("{2}, {1}, {0}", lastname, middlename,
firstname);


The numbers in the brackets tells the compiler which argument in WriteLine
should be placed in that position. So, you should not change the ordering
of {0}, {1}, {2}. Just change the ordering of your arguments like this.

Console.WriteLine("{0}, {1}, {2}", firstname, middlename, lastname);

Console.WriteLine("{0}, {1}, {2}", lastname, firstname, middlename);

Console.WriteLine("{0}, {1}, {2}", lastname, middlename, firstname);
Nov 29 '05 #5
Thanks you guys!

--
Eric Anderson
"Eric Anderson" <ti*********@email.uophx.edu> wrote in message news:O1**************@TK2MSFTNGP11.phx.gbl...
Hi Guys,

I had posted awhile back that I am a new C# programmer and I have just completed my first program. It's pretty simple, but I'm having a slight problem with it. The program that I made rearranges the order of a persons name after they input it into the console. But for some reason the order of rearrangement that I set does not work the way that I want it to work. If you guys can solve my problem and tell me what I did wrong or did not do, it will be greatly appreciated. Here is my code:

using System;

namespace Name_Rearrange

{

/// <summary>

/// Name Rearranger

/// Program rearranges a persons name

/// Eric Anderson, 11.29.05

/// </summary>

class rearrange

{

static void Main(string[] args)

{

string firstname;

string middlename;

string lastname;

Console.WriteLine("Welcome to the Name Rearranger");

// Add 1 line of space here

Console.WriteLine();

Console.Write("What is your first name? ");

firstname = Console.ReadLine();

Console.Write("What is your middle name? ");

middlename = Console.ReadLine();

Console.Write("What is your last name? ");

lastname = Console.ReadLine();

// Add 1 line of space here

Console.WriteLine();

// Show rearranged name here

Console.WriteLine("{0}, {1}, {2}",firstname,middlename,lastname);

Console.WriteLine("{2}, {0}, {1}",lastname,firstname,middlename);

Console.WriteLine("{2}, {1}, {0}", lastname, middlename, firstname);
// Add 1 line of space here

Console.WriteLine();

// Ask to press enter to end

Console.WriteLine("Thank you for playing");

Console.Write("Please press the enter key to exit!");

Console.ReadLine();

}// End Main

}// End Class

}// End Namespace
--
Eric Anderson
Nov 29 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Daniel Chartier | last post: by
11 posts views Thread by | last post: by
reply views Thread by Christian McArdle | last post: by
reply views Thread by Christian McArdle | last post: by
3 posts views Thread by Christian McArdle | last post: by
29 posts views Thread by jeffc | last post: by
5 posts views Thread by jrefactors | last post: by
72 posts views Thread by E. Robert Tisdale | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.