-1

So I am trying to input 4 numbers and have the console readline show it, but when it does, it doesn't separate the numbers.

already tried putting commas in between Firstvalue, Secondvalue, Thirdvalue, and Fourth value but when I do, it only shows the first value.

using System;

namespace ProcessGrades
{
    class Program
    {
        static void Main(string[] args)
        {
            int Firstvalue = 70;
            int Secondvalue = 60;
            int Thirdvalue = 30;
            int Fourthvalue= 45;

            Console.WriteLine("You entered: " + Firstvalue + Secondvalue + Thirdvalue + Fourthvalue);
            Console.WriteLine("Highest grade: ");
            Console.WriteLine("Lowest grade: ");
            Console.WriteLine("Average grade: ");
        }
    }
}

I expect for it to say 70, 60, 30, 40. Not 70603045

spender
  • 117,338
  • 33
  • 229
  • 351
  • At it's simplest `Console.WriteLine("You entered: " + Firstvalue + "," + Secondvalue + "," + Thirdvalue + "etc...")` – spender Sep 22 '19 at 23:14
  • As it happens, there are many different ways for format a string in .NET so that values are separated by commas. The documentation actually covers all of them. See marked duplicates for examples. – Peter Duniho Sep 22 '19 at 23:27

1 Answers1

1

The + concatenates the value, so no space is added.

You can do this:

using System;

namespace ProcessGrades
{
    class Program
    {
        static void Main(string[] args)
        {
            int Firstvalue = 70;
            int Secondvalue = 60;
            int Thirdvalue = 30;
            int Fourthvalue= 45;

            Console.WriteLine($"You entered: {Firstvalue}, {Secondvalue}, {Thirdvalue} and {Fourthvalue}");
            Console.WriteLine("Highest grade: ");
            Console.WriteLine("Lowest grade: ");
            Console.WriteLine("Average grade: ");
        }
    }
}
Carlos Garcia
  • 2,771
  • 1
  • 17
  • 32
  • 1
    This feature is called *string interpolation*. You can read up on it here: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated – spender Sep 22 '19 at 23:15
  • Exactly. I personally found that it was more intuitive among people that were starting into programming than concatenating – Carlos Garcia Sep 22 '19 at 23:17