Answer to Question #254119 in C# for Kayla

Question #254119
Print isosceles triangles. For each triangle, allow the user to input two values: a character to be used for printing the triangle and the size of the peak for the triangle. Test the input for valid characters. The size of the triangle should not be larger than 10. If an invalid non-numeric charac- ter is entered for size or if the value entered for size is larger than 10, use 3 as the default value. If an invalid entry is entered for the character, use an asterisk (*) as the default character. Allow multiple triangles to be printed. For example, if the user inputs # for the character and 6 for the peak, you should produce the following display:

#
##
###
####
#####
######
#####
####
###
##
#à ƒ ƒ ƒ ¢ € ‹
1
Expert's answer
2021-10-20T15:58:24-0400
using System;
using System.Collections.Generic;


namespace App
{








    class Program
    {
        static void Main(string[] args)
        {
            //The size of the triangle should not be larger than 10.
            int size = -1;
            Console.Write("Enter the size of the triangle: ");
            if (!int.TryParse(Console.ReadLine(), out size) || size > 10)
            {
                size = 3;
            }


            Console.Write("Enter the character of the triangle: ");
            string character = Console.ReadLine();
            if (character.Length > 1 || Char.IsDigit(character[0]))
            {
                character = "*";
            }
            for (int i = 1; i <= size; i++)
            {
                for (int j = 0; j < i; j++)
                {
                    Console.Write(character);
                }
                Console.WriteLine();
            }
            for (int i = size-1; i >= 1; i--)
            {
                for (int j = 0; j < i; j++)
                {
                    Console.Write(character);
                }
                Console.WriteLine();
            }


            Console.ReadLine();
        }


    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS