C# Console.WriteLine not printing in one line

c# console.writeline multiple variables
console.writeline c#
c# console.writeline format
c# console.writeline not working
console.writeline new line
console writeline
console.readline c#
console.writeline java

Now if you run this it does not output each Console.WriteLine in one line, why? I know console.writeline goes to next line when done but the problem is it jumps to next line while printing when it print the exception var it is not in the same line as the rest of the writeline The error occurs inside the Display() function at the number 6 variable (exception) it is not in the same line as the rest of the writeline, why?

And also there are no line breaks where the error ocurs.

Ans can be any number you like.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace EquationSolver
{
    class Program
    {
        public static string exception = "No Solution Found yet";
        public static int go = 40;
        public static Decimal x = 0, formul = 0;
        public static Decimal pref = -100000, next = 100000,ans;
        public static Decimal stepval = next / 10;
        public static Decimal prefrem = 1234567890123.1234567890m, nextrem = 1234567890123.1234567890m;
        public static Decimal nextremfirst = 0;
        public static void Answer()
        {
          Console.WriteLine("Enter ans");
          ans = (Convert.ToDecimal(Console.ReadLine()));

        }
        public static void Main(string[] args)
        {
            //Console.WriteLine("Enter ans");
            //Answer(Convert.ToDecimal(Console.ReadLine()));
            Answer();
            //Console.Clear();

            while (true)
            {
                for (var i = 0; i <= go; i++)
                {
                    for (x = pref; x <= next; x += stepval)
                    {
                        formul = x;
                        if (formul < ans)
                            prefrem = x;
                        else if (formul > ans)
                        {
                            if (nextremfirst == 0)
                            {
                                nextrem = x;
                                nextremfirst += 2;
                            }
                        }
                        else if (formul == ans)
                        {
                            AnsFound();
                            break;
                        }
                        else
                        {
                            Error();
                        }
                        Display();
                    }

                    if (formul == ans)
                    {
                        AnsFound();
                        break;
                    }
                    if (prefrem != 1234567890123.1234567890m)
                        pref = prefrem;
                    if (nextrem != 1234567890123.1234567890m)
                        next = nextrem;
                    nextremfirst = 0;
                    stepval /= 10;
                    if (formul != ans)
                        NoAnsyet();

                    //Console.WriteLine();
                }
                Finnish();
            }
        }
        public static void Display()
        {
            //Console.ReadKey();
            //Console.WriteLine("Formul: {0} x: {1} Ans: {2} Status: {3}", //formul, x, ans, exception);

//Here is the error:
            Console.WriteLine("Pref:{0} Next:{1} Step:{2} Formul:{3} x:{4} Ans:{5} Status:{6}",pref,next,stepval,formul,x,ans,exception);
        }
        public static void Finnish()
        {
            if (formul != ans)
                Error();
            exception = "\ncomplete";
            Console.WriteLine(exception);
            pref = -100000;
            next =  100000;
            stepval = next /= 10;
            Console.ReadKey();
            Console.Clear();
            //Console.WriteLine("Enter ans:");
            //Answer(Convert.ToDecimal(Console.ReadLine()));
            Answer();
        }
        public static void AnsFound()
        {
            exception = "\nSolution Found!";
            //Console.WriteLine("x: {0} Ans: {1} Status: {2}", x, ans, exception);
            //Console.WriteLine("Pref:{0} Next: {1} Stepval: {2}     Formul:{3} x:{4} Ans:{5}  Status:{}", pref, next, stepval, formul, x, ans, exception);

        }
        public static void NoAnsyet()
        {
            exception = "\nNo Solution yet...";
            //Console.WriteLine(exception);
        }
        public static void Error()
        {
            exception = "\nNo Solution error!!";
            Console.WriteLine(exception);
        }
    }
}

Because you set exception = "\ncomplete"; at different places. The \n at the beginning is a new line character.

Remove the \n

exception = "complete";

Same problem with other texts like "\nSolution Found!".


Using string interpolation makes string formatting more readable:

Replace

Console.WriteLine("Pref:{0} Next:{1} Step:{2} Formul:{3} x:{4} Ans:{5} Status:{6}",
    pref, next, stepval, formul, x, ans, exception);

by

Console.WriteLine(
$"Pref:{pref} Next:{next} Step:{stepval} Formul:{formul} x:{x} Ans:{ans} Status:{exception}");

Console.WriteLine Method (System), WriteLine in one line, why? I know console.writeline goes to next line when done but the problem is it jumps to next line while printing when it print the exception  Remarks. The default line terminator is a string whose value is a carriage return followed by a line feed ("\r " in C#, or vbCrLf in Visual Basic). You can change the line terminator by setting the TextWriter.NewLine property of the Out property to another string.


WriteLine writes in a New Line. You should try

Console.Write()

If you want to print right after your previous print.

C# Console.Write, Append With No Newline, Writes the specified string value, followed by the current line terminator, to the standard output stream. the specified single-precision floating-point value, followed by the current line C# Copy. // This code example demonstrates the Console.WriteLine() method index plus count specify a position that is not within buffer . Now if you run this it does not output each Console.WriteLine in one line, why? I know console.writeline goes to next line when done but the problem is it jumps to next line while printing when it


The value to your variable exception is the reason why the console is printing on a different basically if you put a special character \n means new line hence all the methods you are calling have this special character.

Solution remove special characters and use the Console.WriteLine or Console.Write methods

C# Console.WriteLine (Print), Write and Console.WriteLine. We decide which one to choose. We even use them The Write method does not append a newline to the end of the Console. Also: If you are printing a string that already has a newline, you can use Console. Console.Write("Two "); // <-- This is on the same line. Console.Write("​Three");  Benchmark, console. In many simple console programs, the Console.WriteLine may be one of the biggest slowdowns. Here we time 100 lines written to the console.


As per the code provided you have not called the method i made some changes to the code Edited code and try to run the code status :No solution found yet Thanks

How to read and write in Console app in C#, Console.WriteLine renders a line of text. Console.Write omits the newline. Part 1: Here we print an int to the screen with Console.WriteLine. A newline comes on the same line. Write() does not append a newline to the end.Console.Write. The Console.Write method requires the System namespace to be included at the top to get the fully qualified name. The Write method does not append a newline to the end of the Console.Using System. Also: If you are printing a string that already has a newline, you can use Console.Write for an entire line.


C# for Programmers, WriteLine() also makes control move to the next line while Console.Write() Date and time is : "+dat); //prints text but keeps cursor in same line Console. ReadLine(); //check if line is empty or not if (line != null && line != First we need start the application and after that, we are able to create instances of classes. The Main() method has the args argument, which stores command line arguments. Console.WriteLine("This is C#"); In this code line, we print the "This is C#" string to the console.


8.2. Examples With for Statements, Line 2 // Printing one line of text with multiple statements. is a comment stating the purpose The first statement uses Console's method Write to display a string. Unlike WriteLine, after displaying its argument, Write does not position the screen​  C# Console.WriteLine These C# example programs show the Console.WriteLine method. Console.WriteLine has many overloads. Console.WriteLine renders a line of text on the console. It is a useful Console method. In its simplest form it outputs the string argument with a trailing newline. With no arguments it outputs a blank line. Example.


C# basics - covering basics of CSharp, C# and many other languages allow a shorter version: Console.WriteLine("{0,2​}{1,8}{2,8}{3,8}", "n", "square", "cube", "root"); for ( int n = 1; n <= 10; n++) { Console. If you run this in csharp, the first line printed does not appear to have a  There are three statements inside of Main and the first two are different from the third. They are Console.Write(…) instead of Console.WriteLine(…).The difference is that the Console.Write(…) statement writes to the console and stops on the same line, but the Console.WriteLine(…) goes to the next line after writing to the console.