``````I am beginner and still learning c++. So this was a question in my assignment to make a horizontal bar chart something like this,
Example:
Input:
N1=>8 , N2=>6 , N3=>2 , N4=>10 , N5=>9
10       *
09       * *
08 *     * *
07 *     * *
06 * *   * *
05 * *   * *
04 * *   * *
03 * *   * *
02 * * * * *
01 * * * * *
1 2 3 4 5

The columns are constant i.e 5 columns. This should be done without arrays as they are not allowed in the assignment and only using loops. It would be much appreciated if someone helps.``````

## All 4 Replies

So the if statement can't be used? Harsh assignment there. Remember I have to take your words as they fell.

commented: We can use if statement and other basic tools +0

OK we can use the various loops and IF. Remember we have many design choices here but the goal is NOT to design well here as the assignment forbid arrays.

So we know we have 10 data lines to output so the first ten lines would be our loop.

I can't write code for you since that's your work so psuedo code will suffice.

``````for row from 10 to 1
{
output row and a space
if n1 => row print a star and space else print two spaces.
if n2 => row print a star and space else print two spaces.
if n3 => row print a star and space else print two spaces.
if n4 => row print a star and space else print two spaces.
if n5 => row print a star.
print the newline
}
Print " 1 2 3 4 5"``````
commented: Thank you. It worked perfectly. +0

Thanks for the report back. Please mark this as solved.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApp2

``````class Program
{

// N1=>8 , N2=>6 , N3=>2 , N4=>10 , N5=>9

//10       *
//09       * *
//08 *     * *
//07 *     * *
//06 * *   * *
//05 * *   * *
//04 * *   * *
//03 * *   * *
//02 * * * * *
//01 * * * * *
//   1 2 3 4 5

static void Main(string[] args)
{

int Rows = 0;
int columns = 0;

int InputNumCount = 0;

Console.Write(\$"Input Rows => ");

Console.Write(\$"Input Colums => ");

Console.Write(\$"Input Num Count => ");

string str = "";

int tempInt = 0;

for (int i = 0; i < InputNumCount; i++)
{
Console.Write("N" + i + "=>");
if (InputNumCount - 1 == i)
{
str += tempInt.ToString();
}
else {
str += tempInt.ToString() + ",";

}

}

string[] StrAry = str.Split(',');
Console.WriteLine();

for (int i = Rows; i > 0; i--)
{
if (i != 10)
{
Console.Write("0" + i + "");
}
else
{
Console.Write(i + "");
}

for (int j = 0; j < columns; j++)
{
if (StrAry.Length <= j)
break;

if (Convert.ToInt32(StrAry[j]) >= i && Convert.ToInt32(StrAry[j]) != 0)
Console.Write("  " + "*");
else {
Console.Write("   ");
}
}

if (i  == 1) {

Console.WriteLine();
Console.Write("    ");

for (int i1 = 1; i1 <= columns; i1++)
{
Console.Write(i1 + "  ");

}
}

Console.WriteLine();
}