simple program

Boiko

Member
Joined
Jan 4, 2014
Messages
8
Location
United Kingdom
Programming Experience
Beginner
Hello I am trying to write just a simple program to show your first and second name, what's wrong with it? Thanks!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace next_lesson
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Please enter your first and second name!");
            string userValue = Console.ReadLine();
            string myFistName = "";
            string mySecondName = "";
            {
                Console.WriteLine("Hello ", userValue = myFistName + mySecondName);
                Console.ReadLine();
            }
        }
    }
}
 
Last edited by a moderator:
Firstly, I have reformatted your code correctly for readability. Please use appropriate formatting tags when posting code snippets in future.

Secondly, while the issue is clear in this case, it may not always be so. Please always explain what you expect to happen AND what actually does happen. That makes it much easier for us to zero in on where the issue is without having to necessarily trawl through all the code.

As for the issue, forget your code for the moment and think about how the program should work from a logical perspective. Firstly, do you want the user to enter their two names separately or together? If you want them separately then I would strongly suggest two separate prompts. If you want them together then you would only use one prompt, but them you would also not need separate variables for the two names. You have one prompt but you also have two variables, so your code is not logical.

I suggest that you do what most beginners don't because it seems like too much work: actually design your app. Pick up a pen and paper and write down the steps the app should perform. Only when that's done should you write any code and you should always check that the code actually does what you wrote. In fact, you should comment the code with quotes from your design so that you can see that it does and which lines of code do what parts of the design.
 
Firstly, I have reformatted your code correctly for readability. Please use appropriate formatting tags when posting code snippets in future.

Secondly, while the issue is clear in this case, it may not always be so. Please always explain what you expect to happen AND what actually does happen. That makes it much easier for us to zero in on where the issue is without having to necessarily trawl through all the code.

As for the issue, forget your code for the moment and think about how the program should work from a logical perspective. Firstly, do you want the user to enter their two names separately or together? If you want them separately then I would strongly suggest two separate prompts. If you want them together then you would only use one prompt, but them you would also not need separate variables for the two names. You have one prompt but you also have two variables, so your code is not logical.

I suggest that you do what most beginners don't because it seems like too much work: actually design your app. Pick up a pen and paper and write down the steps the app should perform. Only when that's done should you write any code and you should always check that the code actually does what you wrote. In fact, you should comment the code with quotes from your design so that you can see that it does and which lines of code do what parts of the design.

Thank You for your replay, as i just started learning c# i don't really know how to make code as it should be. But i will try hard to make it. As i understood i can do this way?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace next_lesson
{
class Program
   {
static void Main(string[] args)
       {
                    Console.WriteLine("Please enter your first and second name!");
                    string userValue = Console.ReadLine();

            {
             Console.WriteLine("Hello ", userValue);
             Console.ReadLine();
            }
    }
}
 
As I said, you should design your application before trying to code it. You have a much better chance of getting the code to do what you want if you have a clear idea of what you want to start with. As I also said, one of the first things to consider is whether you want the user to enter their whole name in one go or their two names separately. You appear to have chosen the former. Does the code actually do what you want? If so then that's great and you're done. If it doesn't then you need to explain, fully and clearly, what it is that you want to happen and how the reality differs from that. We can help but, just like you, we need to know what the code is supposed to do in order to make it do it.
 
Back
Top Bottom