theo123490
theo123490

Reputation: 58

making Console::WriteLine(x) in the same line when looped in CLR console C++

I'm trying to create a pascal triangle using stdafx.h. I come to a problem when trying to put a Console::WriteLine(x) using a loop but wanting it in the same line

I "translated" this from a Iostream C++ empty project

#include "stdafx.h"


using namespace System;

int main(array<System::String ^> ^args)
{ 
int k, i, x, a, b, c, d, e, f, g, h;
Console::WriteLine(L"Number of Rows : ");
String^ strabx = Console::ReadLine();
int n = int::Parse(strabx); //the number of rows
d = 0;
g = 0;
for (i = 0; i <= (n - 1); i++) // i adalah baris 
{
    for (a = (n - i); a >= 1; a--) {
        Console::WriteLine("   ");
    }
    x = 1;
    b = 0;

    e = 0;
    f = 0;
    k = 0;
    do
    {
        f = f + x;

        Console::WriteLine("  " + x + "  ");    //my problem lies here
        x = x * (i - k) / (k + 1);

        b = b + 1; 
        k++;
    } while (k <= i);


    c = b;    
    d = d + c;  
    g = f + g;   
    Console::WriteLine();
}
Console::WriteLine("digit count " + d + "\n");
Console::WriteLine("sums of the number : " + g);

Console::ReadLine();
Console::WriteLine();
}

Upvotes: 0

Views: 558

Answers (1)

timrau
timrau

Reputation: 23058

Use Console::Write() instead.

Console::Write("  " + x + "  ");

Upvotes: 2

Related Questions