Click here to Skip to main content
14,690,512 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
So im a beginner and i need some help. Ive got a task which asks to input an amount of symbols, max symbols in one line and the symbol itself. The problem is that when i input (9->6->*) it prints out:

******
*Press any key to continue . . .

When it should print out
******
***

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

namespace Sav
{
    class Program
    {
        static void Main(string[] args)
        {
            char simbolis;
            int k;
            int x;
            int a = 0;
            Console.Write("iveskite norima kieki: ");
            k = int.Parse(Console.ReadLine());
            Console.Write("iveskite simboliu kieki eiluteje: ");
            x = int.Parse(Console.ReadLine());
            Console.Write("Įveskite spausdinamą simbolį: ");
            simbolis = (char)Console.Read();
            a = k / x;
            int b = k % x;
            for (int i = 1; i <= a; i++)
            {
                for (int j = 1; j<=x; j++)
                {
                        Console.Write(simbolis);
                }
                Console.WriteLine();
            }
            if ( b > 0)
            {
                Console.Write(simbolis);
            }
        }
    }
}


What I have tried:

Spent 10 hours trying to figure out this bs
Posted
Updated 13-Sep-18 7:37am
v2

1 solution

Your main loop will only do the first line, as it goes from 1 to 1. You need to add 1 to a if the value in b is non-zero. Using sensible names for your variables rather than single letters would help to make that clearer. Also, on the last line j should go from 1 to b rather than 1 to x.

Try writing the steps down on paper to get a better idea of what needs to be done.
   
Comments
Member 13975230 13-Sep-18 11:25am
   
Already tried writing on paper, my brain is like a baked egg

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900